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
33 changes: 21 additions & 12 deletions FabricExample/src/screens/Examples/InteractiveKeyboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,30 @@ const useKeyboardAnimation = () => {
const progress = useSharedValue(0);
const height = useSharedValue(0);

useKeyboardHandler({
onMove: (e) => {
"worklet";
useKeyboardHandler(
{
onMove: (e) => {
"worklet";

// eslint-disable-next-line react-compiler/react-compiler
progress.value = e.progress;
height.value = e.height;
},
onInteractive: (e) => {
"worklet";
// eslint-disable-next-line react-compiler/react-compiler
progress.value = e.progress;
height.value = e.height;
},
onInteractive: (e) => {
"worklet";

progress.value = e.progress;
height.value = e.height;
},
onEnd: (e) => {
"worklet";

progress.value = e.progress;
height.value = e.height;
progress.value = e.progress;
height.value = e.height;
},
},
});
[],
);

return { height, progress };
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.reactnativekeyboardcontroller.constants

import kotlin.math.floor

object UIThread {
const val MILLISECONDS_IN_SECOND = 1000.0
const val FPS = 60
val NEXT_FRAME = floor(MILLISECONDS_IN_SECOND / FPS).toLong()
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.UIManagerHelper
import com.facebook.react.views.view.ReactViewGroup
import com.reactnativekeyboardcontroller.constants.Keyboard
import com.reactnativekeyboardcontroller.constants.UIThread
import com.reactnativekeyboardcontroller.events.KeyboardTransitionEvent
import com.reactnativekeyboardcontroller.extensions.appearance
import com.reactnativekeyboardcontroller.extensions.dispatchEvent
Expand Down Expand Up @@ -334,8 +335,8 @@ class KeyboardAnimationCallback(

if (isKeyboardInteractive) {
// in case of interactive keyboard we can not read keyboard frame straight away
// (because we'll always read `0`), so we are posting runnable to the main thread
view.post(runnable)
// (because we'll always read `0`), so we are posting runnable to the next frame on the main thread
view.postDelayed(runnable, UIThread.NEXT_FRAME)
} else {
runnable.run()
}
Expand Down
33 changes: 21 additions & 12 deletions example/src/screens/Examples/InteractiveKeyboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,30 @@ const useKeyboardAnimation = () => {
const progress = useSharedValue(0);
const height = useSharedValue(0);

useKeyboardHandler({
onMove: (e) => {
"worklet";
useKeyboardHandler(
{
onMove: (e) => {
"worklet";

// eslint-disable-next-line react-compiler/react-compiler
progress.value = e.progress;
height.value = e.height;
},
onInteractive: (e) => {
"worklet";
// eslint-disable-next-line react-compiler/react-compiler
progress.value = e.progress;
height.value = e.height;
},
onInteractive: (e) => {
"worklet";

progress.value = e.progress;
height.value = e.height;
},
onEnd: (e) => {
"worklet";

progress.value = e.progress;
height.value = e.height;
progress.value = e.progress;
height.value = e.height;
},
},
});
[],
);

return { height, progress };
};
Expand Down