react-native#KeyboardEvent TypeScript Examples
The following examples show how to use
react-native#KeyboardEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.tsx From react-native-actions-sheet with MIT License | 6 votes |
_onKeyboardShow = (event: KeyboardEvent) => {
if (this.props.keyboardHandlerEnabled) {
this.isRecoiling = true;
let correction = Platform.OS === "android" ? 20 : 5;
this.setState({
keyboard: true,
keyboardPadding: event.endCoordinates.height + correction,
});
waitAsync(300).then(() => {
this.isRecoiling = false;
});
}
};
Example #2
Source File: useKeyboardHeight.ts From jellyfin-audio-player with MIT License | 6 votes |
useKeyboardHeight = () => {
const keyboardHeight = useRef(new Animated.Value(0)).current;
const tabBarHeight = useBottomTabBarHeight();
useEffect(() => {
const keyboardWillShow = (e: KeyboardEvent) => {
Animated.timing(keyboardHeight, {
duration: e.duration,
toValue: tabBarHeight - e.endCoordinates.height,
useNativeDriver: true,
}).start();
};
const keyboardWillHide = (e: KeyboardEvent) => {
Animated.timing(keyboardHeight, {
duration: e.duration,
toValue: 0,
useNativeDriver: true,
}).start();
};
const keyboardWillShowSub = Keyboard.addListener(
'keyboardWillShow',
keyboardWillShow
);
const keyboardWillHideSub = Keyboard.addListener(
'keyboardWillHide',
keyboardWillHide
);
return () => {
keyboardWillHideSub.remove();
keyboardWillShowSub.remove();
};
}, [keyboardHeight, tabBarHeight]);
return keyboardHeight;
}
Example #3
Source File: index.tsx From react-native-bottomsheet-reanimated with MIT License | 6 votes |
useKeyboard = (isEnable = true): [number] => {
const showSubscription = useRef<EmitterSubscription>();
const hideSubscription = useRef<EmitterSubscription>();
const [keyboardHeight, setKeyboardHeight] = useState(0);
function onKeyboardWillShow(e: KeyboardEvent): void {
setKeyboardHeight(e.endCoordinates.height);
}
function onKeyboardWillHide(): void {
setKeyboardHeight(0);
}
useEffect(() => {
if (isEnable) {
const keyboardShowEvent =
Platform.OS === 'android' ? 'keyboardDidShow' : 'keyboardWillShow';
const keyboardHideEvent =
Platform.OS === 'android' ? 'keyboardDidHide' : 'keyboardWillHide';
showSubscription.current = Keyboard.addListener(
keyboardShowEvent,
onKeyboardWillShow
);
hideSubscription.current = Keyboard.addListener(
keyboardHideEvent,
onKeyboardWillHide
);
}
return (): void => {
showSubscription.current?.remove();
hideSubscription.current?.remove();
};
}, [isEnable]);
return [keyboardHeight];
}
Example #4
Source File: index.d.ts From react-native-actions-sheet with MIT License | 5 votes |
_onKeyboardShow: (event: KeyboardEvent) => void;