alexzhirkevich / compose-cupertino

Compose Multiplatform UI components for iOS (Cupertino Widgets)
Apache License 2.0
1.05k stars 35 forks source link

Keyboard Doesn't Open for CupertinoSearchTextField in CupertinoActionSheet or CupertinoAlertDialog #54

Open Micoder-dev opened 3 months ago

Micoder-dev commented 3 months ago

Description When using CupertinoSearchTextField or any text field inside CupertinoActionSheet or CupertinoAlertDialog, the keyboard does not open as expected.

Code Sample Below is a code snippet demonstrating the issue:

val focusRequester = remember { FocusRequester() }

CupertinoActionSheet(
    visible = showChangePasswordSheet,
    onDismissRequest = {
        showChangePasswordSheet = false
    },
    title = {
        CupertinoText("Change Password")
    },
    message = {
        CupertinoText("Enter your old password and new password to change your password.")
    },
    properties = DialogProperties(
        dismissOnBackPress = true,
        dismissOnClickOutside = true
    )
) {

    default(onClick = {}) {
        CupertinoSearchTextField(
            modifier = Modifier.focusRequester(focusRequester).focusable(true),
            value = oldPassword,
            onValueChange = {
                oldPassword = it
            },
            paddingValues = CupertinoSearchTextFieldDefaults.PaddingValues,
            cancelButton = {},
            placeholder = {
                CupertinoText("Old Password")
            },
            leadingIcon = {},
        )

        LaunchedEffect(Unit) {
            delay(500)
            focusRequester.requestFocus()
        }

    }

    default(onClick = {}) {
        CupertinoSearchTextField(
            value = oldPassword,
            onValueChange = {
                oldPassword = it
            },
            paddingValues = CupertinoSearchTextFieldDefaults.PaddingValues,
            cancelButton = {},
            placeholder = {
                CupertinoText("New Password")
            },
            leadingIcon = {},
        )
    }

    default(onClick = {}) {
        CupertinoSearchTextField(
            value = oldPassword,
            onValueChange = {
                oldPassword = it
            },
            paddingValues = CupertinoSearchTextFieldDefaults.PaddingValues,
            cancelButton = {},
            placeholder = {
                CupertinoText("Confirm Password")
            },
            leadingIcon = {},
        )
    }

    default(
        onClick = {}
    ) {
        CupertinoText("Confirm")
    }
    cancel(
        onClick = {
            showChangePasswordSheet = false
        }
    ) {
        CupertinoText("Cancel")
    }
}

Steps to Reproduce

Expected Behavior The keyboard should open automatically when focusing on the CupertinoSearchTextField.

Actual Behavior The keyboard does not open when focusing on the CupertinoSearchTextField.

Additional Information Using LaunchedEffect with a delay and focusRequester.requestFocus() does not resolve the issue.

Any help or workaround for this issue would be greatly appreciated.

alexzhirkevich commented 3 months ago

Action sheet is not designed to be used with interactive content inside actions. Use modal sheets instead. Or try to set enabled to false for sheet actions

Micoder-dev commented 3 months ago
  • CupertinoActionSheet

I tried setting enabled to false for the sheet actions, but it doesn't resolve the issue. While modal bottom sheets work fine, using text fields inside CupertinoActionSheet looks really cool and enhances the user experience for certain use cases.

Would it be possible to consider creating a new widget specifically designed to handle interactive content like text fields within CupertinoActionSheet? This feature would be highly beneficial and may be required for various occasions.

Thank you for your consideration!