1

Hello I'm trying to use useAnimatedKayboard() hook from reanimated 2, everything works fine until I click r to reload the project. The app crashes in android and in ios. I'm using it exactly the same as the doc:

function AnimatedKeyboardExample() {
    const keyboard = useAnimatedKeyboard();
    const translateStyle = useAnimatedStyle(() => {
    return {
        transform: [{ translateY: -keyboard.height.value }],
    };
});

return (
    <ScrollView contentContainerStyle={{flex: 1, justifyContent: 'center', 
alignItems: 'center' }}>
        <Animated.View style={translateStyle}>
            <TextInput />
        </Animated.View>
    </ScrollView>
    );
}

Does anyone know how to resolve this?

EDIT: this is a new project in Expo

Erjon
  • 923
  • 2
  • 7
  • 32

1 Answers1

1

useAnimatedKeyboard is a Reanimated 3 feature, you're using Reanimated 2, which doesn't have it. The app crashes are most likely from calling the undefined function. If you can upgrade to Reanimated 3, that's probably your quickest solution.

The docs you linked aren't super obvious about it, but they are from the "next" version, which is 3.0. If you click through to the docs from the current release, you'll see it's not in the Hooks section.

Abe
  • 4,500
  • 2
  • 11
  • 25
  • You are right, anyway, I tried to migrate from reanimated 2.12.0 to reanimated 3 and there is still this problem. When I reload the project by pressing R in the terminal it crashes both android and ios. Maybe I should wait for a further update from the library. I don't think there is any problem with my project cause I've just created it. – Erjon Feb 18 '23 at 12:28
  • Did you rebuild the project after upgrading? The library uses native code, so the project has to be rebuilt. Try clearing your caches also. – Abe Feb 18 '23 at 17:08
  • Yes, I rebuild it, I even opened it in Android Studio. And I switched `newArchEnabled`to true I gradle.properties. I Cleaned and tried to build again and it failed cause it's asking to install `expo-modules-core`. Even in doing so, the project is broken. I reverted everything to point 0 and I made my own hook quite similar to useAnimatedKeyboard – Erjon Feb 18 '23 at 17:21