Skip to content

Commit dbe3995

Browse files
authored
Fix animation options field casting (#2713)
Fixes https://youtrack.jetbrains.com/issue/CMP-9548/NullPointerException-in-KeyboardVisibilityListener-when-keyboard-notification-has-nil-userInfo ## Release Notes ### Fixes - iOS - Fix crash when manually posting UIKeyboardWillHideNotification without userInfo
1 parent e6f5ba0 commit dbe3995

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

compose/ui/ui/src/iosMain/kotlin/androidx/compose/ui/window/KeyboardVisibilityListener.ios.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import platform.UIKit.UIKeyboardFrameEndUserInfoKey
3434
import platform.UIKit.UIKeyboardWillChangeFrameNotification
3535
import platform.UIKit.UIKeyboardWillHideNotification
3636
import platform.UIKit.UIKeyboardWillShowNotification
37+
import platform.UIKit.UIViewAnimationOptionCurveEaseInOut
3738
import platform.UIKit.UIViewAnimationOptions
3839
import platform.darwin.NSObject
3940

@@ -143,6 +144,6 @@ private class NativeKeyboardVisibilityListener : NSObject() {
143144
private val NSNotification.animationOptions: UIViewAnimationOptions
144145
get() {
145146
val value = userInfo?.get(UIKeyboardAnimationCurveUserInfoKey) as? NSNumber
146-
return value?.unsignedIntegerValue() as UIViewAnimationOptions
147+
return value?.unsignedIntegerValue() ?: UIViewAnimationOptionCurveEaseInOut
147148
}
148149
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2026 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package androidx.compose.ui.keyboard
18+
19+
import androidx.compose.foundation.layout.fillMaxSize
20+
import androidx.compose.foundation.layout.imePadding
21+
import androidx.compose.material.Text
22+
import androidx.compose.ui.Modifier
23+
import androidx.compose.ui.test.runUIKitInstrumentedTest
24+
import kotlin.test.Test
25+
import platform.Foundation.NSNotificationCenter
26+
import platform.UIKit.UIKeyboardWillHideNotification
27+
import platform.UIKit.UIKeyboardWillShowNotification
28+
29+
class KeyboardNotificationsHandleTest {
30+
@Test
31+
fun testKeyboardNotificationsHandle() = runUIKitInstrumentedTest {
32+
setContent {
33+
Text("Compose", modifier = Modifier.fillMaxSize().imePadding())
34+
}
35+
36+
NSNotificationCenter.defaultCenter.postNotificationName(
37+
UIKeyboardWillShowNotification,
38+
null
39+
)
40+
waitForIdle()
41+
// Should not crash
42+
43+
NSNotificationCenter.defaultCenter.postNotificationName(
44+
UIKeyboardWillHideNotification,
45+
null
46+
)
47+
waitForIdle()
48+
// Should not crash
49+
}
50+
}

0 commit comments

Comments
 (0)