Skip to content

Commit 3f9990e

Browse files
committed
fix: don't warn users about the Keyboard API (#71)
1 parent 30e63ca commit 3f9990e

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

packages/react-native/Libraries/Components/Keyboard/Keyboard.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import NativeEventEmitter from '../../EventEmitter/NativeEventEmitter';
1414
import LayoutAnimation from '../../LayoutAnimation/LayoutAnimation';
1515
import dismissKeyboard from '../../Utilities/dismissKeyboard';
1616
import Platform from '../../Utilities/Platform';
17-
import NativeKeyboardObserver from './NativeKeyboardObserver';
1817
import warnOnce from '../../Utilities/warnOnce';
18+
import NativeKeyboardObserver from './NativeKeyboardObserver';
1919

2020
export type KeyboardEventName = $Keys<KeyboardEventDefinitions>;
2121

@@ -116,10 +116,6 @@ class Keyboard {
116116

117117
constructor() {
118118
if (Platform.isVisionOS) {
119-
warnOnce(
120-
'Keyboard-unavailable',
121-
'Keyboard is not available on visionOS platform. The system displays the keyboard in a separate window, leaving the app’s window unaffected by the keyboard’s appearance and disappearance',
122-
);
123119
return;
124120
}
125121

@@ -161,7 +157,11 @@ class Keyboard {
161157
context?: mixed,
162158
): EventSubscription {
163159
if (Platform.isVisionOS) {
164-
return;
160+
warnOnce(
161+
'Keyboard-unavailable',
162+
'Keyboard API is not available on visionOS platform. The system displays the keyboard in a separate window, leaving the app’s window unaffected by the keyboard’s appearance and disappearance',
163+
);
164+
return {remove() {}};
165165
}
166166

167167
return this._emitter.addListener(eventType, listener);

packages/react-native/Libraries/Components/ScrollView/ScrollView.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -776,22 +776,24 @@ class ScrollView extends React.Component<Props, State> {
776776
this._keyboardMetrics = Keyboard.metrics();
777777
this._additionalScrollOffset = 0;
778778

779-
this._subscriptionKeyboardWillShow = Keyboard.addListener(
780-
'keyboardWillShow',
781-
this.scrollResponderKeyboardWillShow,
782-
);
783-
this._subscriptionKeyboardWillHide = Keyboard.addListener(
784-
'keyboardWillHide',
785-
this.scrollResponderKeyboardWillHide,
786-
);
787-
this._subscriptionKeyboardDidShow = Keyboard.addListener(
788-
'keyboardDidShow',
789-
this.scrollResponderKeyboardDidShow,
790-
);
791-
this._subscriptionKeyboardDidHide = Keyboard.addListener(
792-
'keyboardDidHide',
793-
this.scrollResponderKeyboardDidHide,
794-
);
779+
if (Platform.isVisionOS) {
780+
this._subscriptionKeyboardWillShow = Keyboard.addListener(
781+
'keyboardWillShow',
782+
this.scrollResponderKeyboardWillShow,
783+
);
784+
this._subscriptionKeyboardWillHide = Keyboard.addListener(
785+
'keyboardWillHide',
786+
this.scrollResponderKeyboardWillHide,
787+
);
788+
this._subscriptionKeyboardDidShow = Keyboard.addListener(
789+
'keyboardDidShow',
790+
this.scrollResponderKeyboardDidShow,
791+
);
792+
this._subscriptionKeyboardDidHide = Keyboard.addListener(
793+
'keyboardDidHide',
794+
this.scrollResponderKeyboardDidHide,
795+
);
796+
}
795797

796798
this._updateAnimatedNodeAttachment();
797799
}

0 commit comments

Comments
 (0)