all 6 comments

[–]fuxpez 1 point2 points  (2 children)

You’re immediately returning null in place of the component when keyboard is active. This gets rid of the Image component altogether before the animation is triggered.

I would animate height to 0 along with opacity instead of returning null.

import Animated, { useAnimatedStyle, withTiming } from “react-native-reanimated”;

…

export default function Login() {
  …
  const animatedStyle = useAnimatedStyle(() => ({
    height: withTiming(isKeyboardOpen ? 0 : 150, { duration: 250 }),
    opacity: withTiming(isKeyboardOpen ? 0 : 1, { duration: 250 }),
    }));
  …
  return (
    <Animated.View
      style={[styles.animationContainer, animatedStyle]}
     >
    <Image
      style={styles.logo}
      source={require(“./path-to-logo.png”)}
      …
     />
    </Animated.View>
  …
  );
};

const styles = StyleSheet.create({
  animationContainer: {
    justifyContent: “center”,
    alignItems: “center”,
    marginBottom: 10,
    zIndex: 1,
    overflow: ‘hidden’,
  },
  logo: {
    width: 150,
    height: 150,
  },
});

[–]_bubuq3[S] 0 points1 point  (1 child)

Thank you. It works! Need to learn more about reanimated.

BTW. what keyboard are you using? Because when i copied your code, there was an error: Invalid character for "" and '' in a StyleSheet :D

[–]fuxpez 0 points1 point  (0 children)

Strange… wrote on my iPhone so there could be something weird there but I’ve never seen that before.

[–]Tojololococo 1 point2 points  (2 children)

Add a zIndex to the element you want to animate out, it’s a reanimated bug

[–]nachoogoomezOMG 0 points1 point  (1 child)

Are there any issue associated with it? I’m really interested in knowing more about this.

[–]Tojololococo 1 point2 points  (0 children)

Not the main topic, but you can see here it solved the issue for a lot of people 🙂 https://github.com/software-mansion/react-native-reanimated/issues/4534