-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RNKC-080] - telegram keyboard transition (#92)
## 馃摐 Description Added example of custom keyboard animation that actively used in Telegram app. ## 馃挕 Motivation and Context I always was impressed of keyboard animation smoothness on my Android 9 device. So I dig into Android implementation and ported it to react-native 馃槃 ## 馃摙 Changelog ### JS - added toggler for switching keyboard interpolator (platform, telegram) ## 馃 How Has This Been Tested? Tested manually on: - Pixel 2 (emulator, API 28); - Pixel 3 (emulator, API 32); - Xiaomi Redmi note 5 Pro (real device, API 28); - iPhone 11 Pro (simulator, iOS 15.5). ## 馃摳 Screenshots (if appropriate): https://user-images.githubusercontent.com/22820318/195857524-d7a966b9-6b24-43cc-8f82-59d3589dcc12.mov ## 馃摑 Checklist - [x] CI successfully passed
- Loading branch information
1 parent
f93b6be
commit 0d82804
Showing
8 changed files
with
154 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
FabricExample/src/screens/Examples/ReanimatedChat/hooks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Platform } from 'react-native'; | ||
import { useKeyboardHandler } from 'react-native-keyboard-controller'; | ||
import { Easing, useSharedValue, withTiming } from 'react-native-reanimated'; | ||
|
||
export const useTelegramTransitions = () => { | ||
const height = useSharedValue(0); | ||
|
||
useKeyboardHandler( | ||
{ | ||
onStart: (e) => { | ||
'worklet'; | ||
|
||
if (Platform.OS === 'android') { | ||
// on Android Telegram is not using androidx.core values and uses custom interpolation | ||
// duration is taken from here: https://github.com/DrKLO/Telegram/blob/e9a35cea54c06277c69d41b8e25d94b5d7ede065/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/AdjustPanLayoutHelper.java#L39 | ||
// and bezier is taken from: https://github.com/DrKLO/Telegram/blob/e9a35cea54c06277c69d41b8e25d94b5d7ede065/TMessagesProj/src/main/java/androidx/recyclerview/widget/ChatListItemAnimator.java#L40 | ||
height.value = withTiming(-e.height, { | ||
duration: 250, | ||
easing: Easing.bezier( | ||
0.19919472913616398, | ||
0.010644531250000006, | ||
0.27920937042459737, | ||
0.91025390625 | ||
), | ||
}); | ||
} else { | ||
// on iOS Telegram simply moves TextInput synchronously with the content | ||
// to achieve such behavior we are instantly change `height.value` to keyboard | ||
// final frame - iOS will schedule layout animation and it will move the content | ||
// altogether with the keyboard | ||
height.value = -e.height; | ||
} | ||
}, | ||
}, | ||
[] | ||
); | ||
|
||
return { height }; | ||
}; |
39 changes: 34 additions & 5 deletions
39
FabricExample/src/screens/Examples/ReanimatedChat/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Platform } from 'react-native'; | ||
import { useKeyboardHandler } from 'react-native-keyboard-controller'; | ||
import { Easing, useSharedValue, withTiming } from 'react-native-reanimated'; | ||
|
||
export const useTelegramTransitions = () => { | ||
const height = useSharedValue(0); | ||
|
||
useKeyboardHandler( | ||
{ | ||
onStart: (e) => { | ||
'worklet'; | ||
|
||
if (Platform.OS === 'android') { | ||
// on Android Telegram is not using androidx.core values and uses custom interpolation | ||
// duration is taken from here: https://github.com/DrKLO/Telegram/blob/e9a35cea54c06277c69d41b8e25d94b5d7ede065/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/AdjustPanLayoutHelper.java#L39 | ||
// and bezier is taken from: https://github.com/DrKLO/Telegram/blob/e9a35cea54c06277c69d41b8e25d94b5d7ede065/TMessagesProj/src/main/java/androidx/recyclerview/widget/ChatListItemAnimator.java#L40 | ||
height.value = withTiming(-e.height, { | ||
duration: 250, | ||
easing: Easing.bezier( | ||
0.19919472913616398, | ||
0.010644531250000006, | ||
0.27920937042459737, | ||
0.91025390625 | ||
), | ||
}); | ||
} else { | ||
// on iOS Telegram simply moves TextInput synchronously with the content | ||
// to achieve such behavior we are instantly change `height.value` to keyboard | ||
// final frame - iOS will schedule layout animation and it will move the content | ||
// altogether with the keyboard | ||
height.value = -e.height; | ||
} | ||
}, | ||
}, | ||
[] | ||
); | ||
|
||
return { height }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters