Fixed
Status Update
Comments
tc...@google.com <tc...@google.com> #2
Hi Ralston. Can you please update the status of this bug? Either mark it as fixed or move it to a new iteration. Thanks!
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-main
commit ce33078fc5d89cc0bef2fe0b4118f9dd23852654
Author: Ralston Da Silva <ralu@google.com>
Date: Tue Nov 17 16:09:26 2020
API Changes to KeyEvent
This CL does a few things:
1. Prevents false positives:
The current API can lead to false positives. The Compose
"KeyEvent" has a "Key" property. If we don't have a
matching "Key" value, (i.e. the platform sends us an
unknown key), we currently use Key.Unknown to represent
it. This has the drawback that two different unknown
keys map to the same value. For example, if a platform
does not have Key.Home, then the condition
if(keyEvent.key == Key.Home) { ... }
will pass for any unknown key. The root cause is that
"Key" is a property, and it has to be set even if it
is not supported on a particular platform. This CL
changes this API to:
if(keyEvent.isKey(Key.A)) { ... }
Now the different platforms are not forced to populate
the property with some default value but just have to
return false when the key is unknown.
2. Ability to distinguish between left and right Alt keys
We Currently use an integer "keycode" to distinguish between
different keys. This works fine for Android because every
key has a unique keycode. The desktop however, uses the same
keycode for left and right "Alt" keys and uses an additional
property called "Location" to distinguish between the left
and right keys. The result is that the left and right Alt
Keys are identical in Compose. Thr root cause is that the
Key class is an inline class (Integer) that forces the
desktop to use an integer to represent each key. Now that
we changed the api to keyEvent.isKey(), the desktop can
provide an implementation that is backed by multiple
properties of its native keyCode.
3. Exposes Native Android and Desktop Key Events
When the API provided with the Compose KeyEvent is not
sufficient, the user should be allowed to access the native
KeyEvent (as an escape hatch). This CL enables that by
adding a property called "nativeKey" which exposes the native
key event.
Bug: 173086397
Bug: 173080474
Test: ./gradlew compose:ui:ui:connectedCheck -P android.testInstrumentationRunnerArguments.class=androidx.compose.ui.input.key.KeyTest
Test: ./gradlew compose:ui:ui:connectedCheck -P android.testInstrumentationRunnerArguments.class=androidx.compose.ui.input.key.AndroidProcessKeyInputTest
Test: ./gradlew compose:ui:ui:connectedCheck -P android.testInstrumentationRunnerArguments.class=androidx.compose.ui.input.key.MetaKeyTest
Test: ./gradlew compose:ui:ui:connectedCheck -P android.testInstrumentationRunnerArguments.class=androidx.compose.ui.input.key.ProcessKeyInputTest
Relnote: "The native keyEvent can now be accessed through keyEvent.nativeKeyEvent"
Change-Id: I87c57d68b76441fe92d2b91f58385832fc40ec8d
M compose/foundation/foundation-layout/api/api_lint.ignore
M compose/integration-tests/docs-snippets/src/main/java/androidx/compose/integration/docs/testing/Testing.kt
D compose/runtime/runtime-saved-instance-state/api/api_lint.ignore
M compose/runtime/runtime/api/api_lint.ignore
M compose/ui/ui-graphics/api/api_lint.ignore
M compose/ui/ui-test-junit4/api/api_lint.ignore
M compose/ui/ui-test/api/current.txt
M compose/ui/ui-test/api/public_plus_experimental_current.txt
M compose/ui/ui-test/api/restricted_current.txt
M compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/KeyInputHelpers.kt
M compose/ui/ui-text/api/api_lint.ignore
M compose/ui/ui/api/api_lint.ignore
M compose/ui/ui/api/current.txt
M compose/ui/ui/api/public_plus_experimental_current.txt
M compose/ui/ui/api/restricted_current.txt
M compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/keyinput/KeyInputDemo.kt
M compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/key/AndroidProcessKeyInputTest.kt
D compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/key/KeyInputUtil.kt
M compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/key/KeyTest.kt
M compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/key/MetaKeyTest.kt
M compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/key/ProcessKeyInputTest.kt
M compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/input/key/Key.kt
A compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/input/key/KeyEvent.kt
D compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/input/key/KeyEventAndroid.kt
M compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidComposeView.kt
M compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/input/key/Key.kt
M compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/input/key/KeyEvent.kt
M compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/input/key/Key.kt
A compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/input/key/KeyEvent.kt
D compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/input/key/KeyEventDesktop.kt
M compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/platform/DesktopOwners.kt
M compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/window/MenuItem.kt
M compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/input/key/KeyInputUtil.kt
A compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/input/key/KeyTest.kt
https://android-review.googlesource.com/1532744
Branch: androidx-main
commit ce33078fc5d89cc0bef2fe0b4118f9dd23852654
Author: Ralston Da Silva <ralu@google.com>
Date: Tue Nov 17 16:09:26 2020
API Changes to KeyEvent
This CL does a few things:
1. Prevents false positives:
The current API can lead to false positives. The Compose
"KeyEvent" has a "Key" property. If we don't have a
matching "Key" value, (i.e. the platform sends us an
unknown key), we currently use Key.Unknown to represent
it. This has the drawback that two different unknown
keys map to the same value. For example, if a platform
does not have Key.Home, then the condition
if(keyEvent.key == Key.Home) { ... }
will pass for any unknown key. The root cause is that
"Key" is a property, and it has to be set even if it
is not supported on a particular platform. This CL
changes this API to:
if(keyEvent.isKey(Key.A)) { ... }
Now the different platforms are not forced to populate
the property with some default value but just have to
return false when the key is unknown.
2. Ability to distinguish between left and right Alt keys
We Currently use an integer "keycode" to distinguish between
different keys. This works fine for Android because every
key has a unique keycode. The desktop however, uses the same
keycode for left and right "Alt" keys and uses an additional
property called "Location" to distinguish between the left
and right keys. The result is that the left and right Alt
Keys are identical in Compose. Thr root cause is that the
Key class is an inline class (Integer) that forces the
desktop to use an integer to represent each key. Now that
we changed the api to keyEvent.isKey(), the desktop can
provide an implementation that is backed by multiple
properties of its native keyCode.
3. Exposes Native Android and Desktop Key Events
When the API provided with the Compose KeyEvent is not
sufficient, the user should be allowed to access the native
KeyEvent (as an escape hatch). This CL enables that by
adding a property called "nativeKey" which exposes the native
key event.
Bug: 173086397
Bug: 173080474
Test: ./gradlew compose:ui:ui:connectedCheck -P android.testInstrumentationRunnerArguments.class=androidx.compose.ui.input.key.KeyTest
Test: ./gradlew compose:ui:ui:connectedCheck -P android.testInstrumentationRunnerArguments.class=androidx.compose.ui.input.key.AndroidProcessKeyInputTest
Test: ./gradlew compose:ui:ui:connectedCheck -P android.testInstrumentationRunnerArguments.class=androidx.compose.ui.input.key.MetaKeyTest
Test: ./gradlew compose:ui:ui:connectedCheck -P android.testInstrumentationRunnerArguments.class=androidx.compose.ui.input.key.ProcessKeyInputTest
Relnote: "The native keyEvent can now be accessed through keyEvent.nativeKeyEvent"
Change-Id: I87c57d68b76441fe92d2b91f58385832fc40ec8d
M compose/foundation/foundation-layout/api/api_lint.ignore
M compose/integration-tests/docs-snippets/src/main/java/androidx/compose/integration/docs/testing/Testing.kt
D compose/runtime/runtime-saved-instance-state/api/api_lint.ignore
M compose/runtime/runtime/api/api_lint.ignore
M compose/ui/ui-graphics/api/api_lint.ignore
M compose/ui/ui-test-junit4/api/api_lint.ignore
M compose/ui/ui-test/api/current.txt
M compose/ui/ui-test/api/public_plus_experimental_current.txt
M compose/ui/ui-test/api/restricted_current.txt
M compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/KeyInputHelpers.kt
M compose/ui/ui-text/api/api_lint.ignore
M compose/ui/ui/api/api_lint.ignore
M compose/ui/ui/api/current.txt
M compose/ui/ui/api/public_plus_experimental_current.txt
M compose/ui/ui/api/restricted_current.txt
M compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/keyinput/KeyInputDemo.kt
M compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/key/AndroidProcessKeyInputTest.kt
D compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/key/KeyInputUtil.kt
M compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/key/KeyTest.kt
M compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/key/MetaKeyTest.kt
M compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/key/ProcessKeyInputTest.kt
M compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/input/key/Key.kt
A compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/input/key/KeyEvent.kt
D compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/input/key/KeyEventAndroid.kt
M compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidComposeView.kt
M compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/input/key/Key.kt
M compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/input/key/KeyEvent.kt
M compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/input/key/Key.kt
A compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/input/key/KeyEvent.kt
D compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/input/key/KeyEventDesktop.kt
M compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/platform/DesktopOwners.kt
M compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/window/MenuItem.kt
M compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/input/key/KeyInputUtil.kt
A compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/input/key/KeyTest.kt
Description
Change the API used to compare keycodes.
Compose Desktop uses multiple fields from AWT's KeyEvent to determine if the Left or Right Modifier key was pressed. Our current API relies on Keycode alone, which is not sufficient for Desktop