forked from androidx/androidx
-
Notifications
You must be signed in to change notification settings - Fork 86
Add API for iOS IME Options #2108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
44446d7
Remove unused UITextInput traits
svastven 7892348
Create API for PlatformImeOptions for iOS
svastven 464ca37
Prefer using platformImeOptions for SkikoUITextInputTraits overrides …
svastven ee9b87c
Update documentation for ImeOptions
svastven 76fb583
Add demo example for iOS Platform IME Options
svastven 87dfe08
Revert documentation changes
svastven 57d663a
Decouple UIKit specific IME options API from PlatformImeOptions actua…
svastven 1451981
Use updated platform ime options API in SkikoUITextInputTraits
svastven b709145
Use updated PlatformImeOptions API in iOS demo example
svastven 785e7c5
Rename PlatformImeOptions uikit file
svastven 21f320b
Annotate new public API with @ExperimentalComposeUiApi
svastven 5e6c412
Opt in to use of experimental API in demo example
svastven e38f6c6
Remove DefaultPlatformImeOptions
svastven 09e0bc2
Remove unused imports
svastven db3e5e8
Dump API
svastven File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
204 changes: 204 additions & 0 deletions
204
compose/mpp/demo/src/uikitMain/kotlin/androidx/compose/mpp/demo/IosImeOptionsExample.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
/* | ||
* Copyright 2025 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package androidx.compose.mpp.demo | ||
|
||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.foundation.lazy.items | ||
import androidx.compose.foundation.text.BasicTextField | ||
import androidx.compose.foundation.text.KeyboardActions | ||
import androidx.compose.foundation.text.KeyboardOptions | ||
import androidx.compose.material.Text | ||
import androidx.compose.mpp.demo.textfield.android.demoTextFieldModifiers | ||
import androidx.compose.mpp.demo.textfield.android.fontSize8 | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.ui.ExperimentalComposeUiApi | ||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.input.PlatformImeOptions | ||
import platform.UIKit.UIKeyboardAppearanceDark | ||
import platform.UIKit.UIKeyboardAppearanceDefault | ||
import platform.UIKit.UIKeyboardAppearanceLight | ||
import platform.UIKit.UIKeyboardTypeDecimalPad | ||
import platform.UIKit.UIKeyboardTypeDefault | ||
import platform.UIKit.UIKeyboardTypeEmailAddress | ||
import platform.UIKit.UIKeyboardTypeNamePhonePad | ||
import platform.UIKit.UIKeyboardTypeNumberPad | ||
import platform.UIKit.UIKeyboardTypePhonePad | ||
import platform.UIKit.UIKeyboardTypeTwitter | ||
import platform.UIKit.UIKeyboardTypeURL | ||
import platform.UIKit.UIKeyboardTypeWebSearch | ||
import platform.UIKit.UIReturnKeyType | ||
import platform.UIKit.UITextAutocapitalizationType | ||
import platform.UIKit.UITextAutocorrectionType | ||
|
||
private val keyboardTypes = listOf( | ||
"Default" to UIKeyboardTypeDefault, | ||
"Email" to UIKeyboardTypeEmailAddress, | ||
"Number" to UIKeyboardTypeNumberPad, | ||
"Phone" to UIKeyboardTypePhonePad, | ||
"Name" to UIKeyboardTypeNamePhonePad, | ||
"URL" to UIKeyboardTypeURL, | ||
"Decimal" to UIKeyboardTypeDecimalPad, | ||
"Twitter" to UIKeyboardTypeTwitter, | ||
"WebSearch" to UIKeyboardTypeWebSearch, | ||
"None" to null, | ||
) | ||
|
||
private val keyboardAppearances = listOf( | ||
"Default" to UIKeyboardAppearanceDefault, | ||
"Light" to UIKeyboardAppearanceLight, | ||
"Dark" to UIKeyboardAppearanceDark, | ||
) | ||
|
||
private val returnKeyTypes = listOf( | ||
"Default" to UIReturnKeyType.UIReturnKeyDefault, | ||
"Go" to UIReturnKeyType.UIReturnKeyGo, | ||
"Join" to UIReturnKeyType.UIReturnKeyJoin, | ||
"Next" to UIReturnKeyType.UIReturnKeyNext, | ||
"Route" to UIReturnKeyType.UIReturnKeyRoute, | ||
"Search" to UIReturnKeyType.UIReturnKeySearch, | ||
"Done" to UIReturnKeyType.UIReturnKeyDone, | ||
"Emergency Call" to UIReturnKeyType.UIReturnKeyEmergencyCall, | ||
"Null" to null | ||
) | ||
|
||
private val autocorrectionTypes = listOf( | ||
"Default" to UITextAutocorrectionType.UITextAutocorrectionTypeDefault, | ||
"No" to UITextAutocorrectionType.UITextAutocorrectionTypeNo, | ||
"Yes" to UITextAutocorrectionType.UITextAutocorrectionTypeYes, | ||
) | ||
|
||
private val autocapitalizationTypes = listOf( | ||
"None" to UITextAutocapitalizationType.UITextAutocapitalizationTypeNone, | ||
"Sentences" to UITextAutocapitalizationType.UITextAutocapitalizationTypeSentences, | ||
"Words" to UITextAutocapitalizationType.UITextAutocapitalizationTypeWords, | ||
"All Characters" to UITextAutocapitalizationType.UITextAutocapitalizationTypeAllCharacters, | ||
"Null" to null | ||
) | ||
|
||
@OptIn(ExperimentalComposeUiApi::class) | ||
private val IosImeOptionsKeyboardTypeExample = Screen.Example("Keyboard Type") { | ||
LazyColumn { | ||
items(keyboardTypes) { | ||
Item(it.first, PlatformImeOptions { keyboardType(it.second) }) | ||
} | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalComposeUiApi::class) | ||
private val IosImeOptionsKeyboardAppearanceExample = Screen.Example("Keyboard Appearance") { | ||
LazyColumn { | ||
items(keyboardAppearances) { | ||
Item(it.first, PlatformImeOptions { keyboardAppearance(it.second) }) | ||
} | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalComposeUiApi::class) | ||
private val IosImeOptionsReturnKeyTypeExample = Screen.Example("Return Key Type") { | ||
LazyColumn { | ||
items(returnKeyTypes) { | ||
Item(it.first, PlatformImeOptions { returnKeyType(it.second) }) | ||
} | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalComposeUiApi::class) | ||
private val IosImeOptionsIsSecureTextEntryExample = Screen.Example("Is Secure Text Entry") { | ||
LazyColumn { | ||
item { Item("Is Secure", PlatformImeOptions { isSecureTextEntry(true) }) } | ||
item { Item("Is Not Secure", PlatformImeOptions { isSecureTextEntry(false) }) } | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalComposeUiApi::class) | ||
private val IosImeOptionsEnablesReturnKeyTypeAutomaticallyExample = Screen.Example("Enables Return Key Type Automatically") { | ||
LazyColumn { | ||
item { | ||
Item( | ||
"Enables Return Key Type Automatically", | ||
PlatformImeOptions { enablesReturnKeyAutomatically(true) } | ||
) | ||
} | ||
item { | ||
Item( | ||
"Doesn't Enable Return Key Type Automatically", | ||
PlatformImeOptions { enablesReturnKeyAutomatically(false) } | ||
) | ||
} | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalComposeUiApi::class) | ||
private val IosImeOptionsAutocapitalizationTypeExample = Screen.Example("Autocapitalization Type") { | ||
LazyColumn { | ||
items(autocapitalizationTypes) { | ||
Item(it.first, PlatformImeOptions { autocapitalizationType(it.second) }) | ||
} | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalComposeUiApi::class) | ||
private val IosImeOptionsAutocorrectionTypeExample = Screen.Example("Autocapitalization Type") { | ||
LazyColumn { | ||
items(autocorrectionTypes) { | ||
Item(it.first, PlatformImeOptions { autocorrectionType(it.second) }) | ||
} | ||
} | ||
} | ||
|
||
val IosImeOptionsExample = Screen.Selection( | ||
"iOS Platform IME Options", | ||
IosImeOptionsKeyboardTypeExample, | ||
IosImeOptionsKeyboardAppearanceExample, | ||
IosImeOptionsReturnKeyTypeExample, | ||
IosImeOptionsIsSecureTextEntryExample, | ||
IosImeOptionsEnablesReturnKeyTypeAutomaticallyExample, | ||
IosImeOptionsAutocapitalizationTypeExample, | ||
IosImeOptionsAutocorrectionTypeExample | ||
) | ||
|
||
@Composable | ||
private fun Item( | ||
title: String, | ||
options: PlatformImeOptions | ||
) { | ||
Text(title) | ||
EditLine(options) | ||
} | ||
|
||
@Composable | ||
private fun EditLine( | ||
options: PlatformImeOptions, | ||
text: String = "" | ||
) { | ||
val keyboardController = LocalSoftwareKeyboardController.current | ||
val state = rememberSaveable { mutableStateOf(text) } | ||
BasicTextField( | ||
modifier = demoTextFieldModifiers, | ||
value = state.value, | ||
singleLine = true, | ||
keyboardOptions = KeyboardOptions( | ||
platformImeOptions = options | ||
), | ||
keyboardActions = KeyboardActions { keyboardController?.hide() }, | ||
onValueChange = { state.value = it }, | ||
textStyle = TextStyle(fontSize = fontSize8), | ||
) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @igordmn for awareness: changing
actual
skiko/non-android variant of an empty (not yet adopted) class toopen
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer adding uikit-only open variant of the
PlatformImeOptions
, keepingfinal
for all other platforms.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not compilation target specific. It's about how non-android variants handle that, so I see no reason to introduce the diff here.
Keep only skiko actual variant was an explicit ask from me above