Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Platform } from 'react-native';
import {
Easing,
useDerivedValue,
useAnimatedReaction,
useSharedValue,
withTiming,
} from 'react-native-reanimated';
Expand Down Expand Up @@ -37,8 +37,11 @@ export const useSmoothKeyboardHandler: typeof useKeyboardHandler = (
const persistedHeight = useSharedValue(0);
const animatedKeyboardHeight = useSharedValue(0);

useDerivedValue(() => {
if (!IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
useAnimatedReaction(
() => {
if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
return;
}
const event = {
// it'll be always 250, since we're running animation via `withTiming` where
// duration in config (TELEGRAM_ANDROID_TIMING_CONFIG.duration) = 250ms
Expand All @@ -47,14 +50,21 @@ export const useSmoothKeyboardHandler: typeof useKeyboardHandler = (
height: animatedKeyboardHeight.value,
progress: animatedKeyboardHeight.value / persistedHeight.value,
};
handler.onMove?.(event);
return event;
},
(evt) => {
if (!evt) {
return;
}
handler.onMove?.(evt);

// dispatch `onEnd`
if (animatedKeyboardHeight.value === persistedHeight.value) {
handler.onEnd?.(event);
handler.onEnd?.(evt);
}
}
}, []);
},
[handler]
);

useKeyboardHandler(
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Platform } from 'react-native';
import {
Easing,
useDerivedValue,
useAnimatedReaction,
useSharedValue,
withTiming,
} from 'react-native-reanimated';
Expand Down Expand Up @@ -37,8 +37,11 @@ export const useSmoothKeyboardHandler: typeof useKeyboardHandler = (
const persistedHeight = useSharedValue(0);
const animatedKeyboardHeight = useSharedValue(0);

useDerivedValue(() => {
if (!IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
useAnimatedReaction(
() => {
if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
return;
}
const event = {
// it'll be always 250, since we're running animation via `withTiming` where
// duration in config (TELEGRAM_ANDROID_TIMING_CONFIG.duration) = 250ms
Expand All @@ -47,14 +50,21 @@ export const useSmoothKeyboardHandler: typeof useKeyboardHandler = (
height: animatedKeyboardHeight.value,
progress: animatedKeyboardHeight.value / persistedHeight.value,
};
handler.onMove?.(event);
return event;
},
(evt) => {
if (!evt) {
return;
}
handler.onMove?.(evt);

// dispatch `onEnd`
if (animatedKeyboardHeight.value === persistedHeight.value) {
handler.onEnd?.(event);
handler.onEnd?.(evt);
}
}
}, []);
},
[handler]
);

useKeyboardHandler(
{
Expand Down