Animated components breaking on refresh and disappearing #3992
Labels
Missing repro
This issue need minimum repro scenario
Needs review
Issue is ready to be reviewed by a maintainer
Platform: Android
This issue is specific to Android
Description
reanimated_bug.mp4
This is exactly whats happening, Animations is fixed if i go back and come to the same screen.I will attach the component code, The issue began when I installed Moti with
npm install moti --legacy-peer-deps
but I uninstalled It since the Animations were not working as expected.This bug is very annoying and really slowing down development also other pages are also breaking when i only refresh this page.The animations dont break when I refresh other screen where I use reanimated.Steps to reproduce
import React, {useState, useEffect, useRef} from 'react'; import { ScrollView, Text, View, StyleSheet, Image, FlatList, useWindowDimensions,
}` from 'react-native';import DynamicHeader from '../../common/components/DynamicHeader/DynamicHeader';
import {SafeAreaView} from 'react-native';
import Animated, {
useAnimatedScrollHandler,
useSharedValue,
useAnimatedStyle,
interpolate,
withTiming,
multiply,
min,
Extrapolate,
interpolateColor,
runOnJS,
useCode,
block,
cond,
greaterOrEq,
and,
lessThan,
set,
useDerivedValue,
useValue,
FadeIn,
FadeOut,
} from 'react-native-reanimated';
import {useAnimatedValues} from 'react-native-reanimated';
import {clamp} from '../../utils/Clamp';
import getApiClient from '../../axios/axios';
import {log} from '../../common/utils';
import {Colors, Typography} from '../../styles';
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome';
import {
faClock,
faStar,
faArrowLeft,
faAngleLeft,
faDotCircle,
} from '@fortawesome/free-solid-svg-icons';
import {TouchableOpacity} from 'react-native-gesture-handler';
import {useNavigation} from '@react-navigation/native';
import CircleLoader from '../../common/components/CircleLoader/CircleLoader';
import Lottie from 'lottie-react-native';
import TimerIcon from '../../assets/TimerIcon.svg';
import ItemCard from './Components/ItemCard';
import Filled from '../../assets/starFilled.svg';
import SectionText from './Components/SectionText';
import FssaiLogo from '../../assets/fssai2.svg';
import {useSelector} from 'react-redux';
/* import {onScrollEvent, useValue} from 'react-native-redash'; */
const FoodStoreDetails = ({route}) => {
const HEADER_HEIGHT = 200;
const progress = useSharedValue(0);
const scrollY = useSharedValue(0);
const offsetY = useSharedValue(0);
const colorprogress = useSharedValue(0);
const foodtypecolorprogress = useSharedValue(0);
const translateXprogress = useSharedValue(0);
const menutitleprogress = useSharedValue(0);
const [menu, setMenu] = useState([]);
const [allMenu, setAllMenu] = useState([]);
const [loading, setLoading] = useState(false);
const [sectionHeights, setSectionHeights] = useState([]);
const [sectionIndex, setSectionIndex] = useState(0);
const [flatListScrollOffset, setFlatListScrollOffset] = useState(0);
const flatListScrollY = useSharedValue(0);
const [foodType, setFoodType] = useState('');
const foodTypeProgress = useSharedValue(0);
const sindex = useSharedValue(0);
const {height, width} = useWindowDimensions();
const handleFlatListOnScroll = e => {
'worklet';
};
/* useEffect(() => {
console.log('index', sectionIndex);
}, [sectionIndex]); */
const handleOnLayout = (index, e) => {
const {height} = e.nativeEvent.layout;
setSectionHeights(prevHeights => {
prevHeights[index] = height;
return [...prevHeights];
});
};
/* const sectionTitleAnimatedStyle = useAnimatedStyle(() => {
}); */
/* const menuProgress = useSharedValue(0) /
const AnimatedFlatlist = Animated.createAnimatedComponent(FlatList);
const scrollHandler = useAnimatedScrollHandler({
onScroll: (event, ctx) => {
if (!ctx.prevY) {
ctx.prevY = 0;
}
const diff = event.contentOffset.y - ctx.prevY;
if (!scrollY?.value) {
scrollY.value = 0;
}
offsetY.value = event.contentOffset.y;
scrollY.value = clamp(scrollY.value + diff, 0, 100);
scrollY.value = event.contentOffset.y;
/ console.log(scrollY.value); */
handleFlatListOnScroll();
ctx.prevY = event.contentOffset.y;
},
});
const animatedStyle = useAnimatedStyle(() => {
if (offsetY.value > 190) {
progress.value = withTiming(1, {
duration: 300,
});
} else {
progress.value = withTiming(0, {
duration: 300,
});
}
if (offsetY.value > 190) {
colorprogress.value = withTiming(1, {
duration: 300,
});
} else {
colorprogress.value = withTiming(0, {
duration: 300,
});
}
const backgroundColor = interpolateColor(
colorprogress.value,
[0, 1],
['#fff', Colors.primary],
);
/* let transform = 200;
if (offsetY.value > 200) {
transform = withTiming(0, {
duration: 300,
});
} /
/ console.log(translateXprogress); */
const elevation = interpolate(progress.value, [0, 1], [0, 7]);
const transformy = interpolate(scrollY.value, [0, 200], [200, 0], {
extrapolateRight: Extrapolate.CLAMP,
});
});
const foodTypeAnimatedStyle = useAnimatedStyle(() => {
const transformy = interpolate(scrollY.value, [0, 375], [425, 50], {
extrapolateRight: Extrapolate.CLAMP,
});
});
const nameAnimationStyle = useAnimatedStyle(() => {
if (offsetY.value > 190) {
translateXprogress.value = withTiming(1, {
duration: 300,
});
} else {
translateXprogress.value = withTiming(0, {
duration: 300,
});
}
const transformx = interpolate(translateXprogress.value, [0, 1], [0, 40], {
extrapolateRight: Extrapolate.CLAMP,
});
const color = interpolateColor(
colorprogress.value,
[0, 1],
['#333', '#fff'],
);
return {
transform: [{translateX: transformx}],
color: color,
};
});
const menuTitleAnimatedStyle = useAnimatedStyle(() => {
if (offsetY.value > 400) {
menutitleprogress.value = withTiming(1, {
duration: 300,
});
} else {
menutitleprogress.value = withTiming(0, {
duration: 300,
});
}
});
const backIconAnimationStyle = useAnimatedStyle(() => {
if (offsetY.value > 190) {
colorprogress.value = withTiming(1, {
duration: 300,
});
} else {
colorprogress.value = withTiming(0, {
duration: 300,
});
}
const transform = interpolate(scrollY.value, [0, 200], [10, 10], {
extrapolateRight: Extrapolate.CLAMP,
extrapolateLeft: Extrapolate.CLAMP,
});
});
const animatedImageStyle = useAnimatedStyle(() => {
const opacity = interpolate(scrollY.value, [70, 200], [1, 0.3], {
extrapolateRight: Extrapolate.CLAMP,
});
return {
opacity: opacity,
};
});
async function getRestaurantDetails() {
const axios = await getApiClient();
setLoading(true);
/* console.log(route?.params?.restaurant?._id); /
const response = await axios.post('/v1/product/all-products', {
store: route.params.restaurant?._id,
});
if (response?.data?.success === true) {
/ log(response?.data?.data?.all_products?.length); */
setMenu(response?.data?.data?.all_products);
setAllMenu(response?.data?.data?.all_products);
setLoading(false);
} else {
console.log(response?.data?.error?.message);
setLoading(false);
alert('something went wrong');
}
}
const navigation = useNavigation();
useEffect(() => {
setLoading(true);
}, []);
const getRating = rating => {
rating = parseFloat(rating);
if (rating < 1.5) {
return 'red';
} else if (rating < 3) {
return '#FA8F1A';
} else {
return '#24963F';
}
};
const cart_items = useSelector(state => state.cart.cart_items);
const [CartItems, setCartItems] = useState([]);
const [CartTotal, setCartTotal] = useState(0);
useEffect(() => {
let arr = cart_items?.filter(
item => item?.store?._id === route.params?.restaurant?._id,
);
setCartItems(arr);
let total = 0;
for (let i = 0; i < arr?.length; i++) {
total = total + parseInt(arr[i]?.product?.price);
}
setCartTotal(total);
}, [cart_items]);
const checkIfClosed = item => {
if (route?.params?.restaurant?.store_status === 'closed_for_orders') {
return 'closed';
}
let current_hour = new Date().getHours();
let current_minute = new Date().getMinutes();
let current_day = new Date().getDay();
let store_start_time = parseFloat(
route?.params?.restaurant?.time?.open_time?.hours +
'.' +
route?.params?.restaurant?.time?.open_time?.minutes
?.toString()
.padStart(2, '0'),
);
let store_close_time = parseFloat(
route?.params?.restaurant?.time?.close_time?.hours +
'.' +
route?.params?.restaurant?.time?.close_time?.minutes
?.toString()
.padStart(2, '0'),
);
};
const handleTypeToggle = type => {
let arr = [];
for (let i = 0; i < allMenu?.length; i++) {
let product_arr = [];
};
if (loading) {
return ;
}
return (
<>
<Animated.View
style={[
{
position: 'absolute',
left: 0,
right: 0,
top: 0,
zIndex: 23,
backgroundColor: '#fff',
paddingHorizontal: 10,
justifyContent: 'center',
height: 50,
},
animatedStyle,
]}>
{checkIfClosed() === 'closed' && (
<Lottie
style={{
position: 'absolute',
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 10,
margin: 0,
},
scrollText: {
fontSize: 19,
textAlign: 'center',
padding: 20,
color: '#000',
},
details_container: {
backgroundColor: '#fff',
padding: 10,
paddingTop: 15,
/* paddingTop: 0, /
backgroundColor: Colors.bg_gray,
/ backgroundColor: 'red', /
},
inner_details_container: {
elevation: 5,
padding: 10,
paddingVertical: 10,
borderRadius: 10,
borderWidth: StyleSheet.hairlineWidth,
borderColor: '#94A3B8',
backgroundColor: '#fff',
flexDirection: 'row',
gap: 5,
justifyContent: 'space-between',
/ marginTop: 15, */
marginTop: 5,
},
delivery_container: {
width: '75%',
},
rating_container: {
width: '25%',
},
triangle: {
width: 0,
height: 0,
backgroundColor: 'transparent',
borderStyle: 'solid',
},
arrowUp: {
borderTopWidth: 0,
borderRightWidth: 4,
borderBottomWidth: 8,
borderLeftWidth: 4,
marginTop: -1,
borderTopColor: 'transparent',
borderRightColor: 'transparent',
borderBottomColor: '#8D2729',
borderLeftColor: 'transparent',
},
});
export default FoodStoreDetails;
`
Snack or a link to a repository
Cannot reproduce
Reanimated version
2.14.4
React Native version
0.71
Platforms
Android
JavaScript runtime
Hermes
Workflow
React Native (without Expo)
Architecture
Paper (Old Architecture)
Build type
Debug mode
Device
Android emulator
Device model
Pixel 4 (Android 11)
Acknowledgements
Yes
The text was updated successfully, but these errors were encountered: