Animation React
Animation React
import Animated, {
useAnimatedScrollHandler,
useAnimatedStyle,
useSharedValue,
} from "react-native-reanimated";
function generateUUID() {
return v.toString(16);
});
function getRandomBoolean() {
function getRandomChatMessage() {
const chatMessages = [
"I'm listening.",
];
return chatMessages[Math.floor(Math.random() * chatMessages.length)];
key: generateUUID(),
text: getRandomChatMessage(),
mine: getRandomBoolean(),
}));
scrollY.value = e.contentOffset.y;
});
// If you don't like inline-styles with Reanimated, add this style to the AnimatedLinearGradientInstead.
return {
transform: [
translateY: scrollY.value,
},
],
};
});
return (
<Animated.ScrollView
onScroll={onScroll}
<AnimatedMaskedView
renderToHardwareTextureAndroid
maskElement={
<View
renderToHardwareTextureAndroid
{data.map((item) => (
<View
key={item.key}
style={[
styles.messageItem,
},
]}>
<Text style={{ opacity: 0 }}>{item.text}</Text>
</View>
))}
</View>
}>
<FlatList
scrollEnabled={false}
data={data}
removeClippedSubviews={true}
return (
<View
style={[
styles.messageItem,
zIndex: item.mine ? -1 : 1, // only display the other messages above the gradient mask, we
want to avoid gradient being applied to the other message other than mine.
},
]}>
</Text>
</View>
);
}}
/>
<AnimatedLinearGradient
style={[
height,
// transform: [
// {
// translateY: onScroll,
// },
// ],
},
gradientStyle,
]}
/>
</View>
</AnimatedMaskedView>
</Animated.ScrollView>
);
};
messageItem: {
paddingHorizontal: 20,
paddingVertical: 12,
margin: 12,
marginBottom: 8,
borderRadius: 12,
},
});