Thursday, December 21, 2023
HomeiOS DevelopmentWhy am I getting a crash when utilizing react-native-linear-gradient ONLY on iOS...

Why am I getting a crash when utilizing react-native-linear-gradient ONLY on iOS 17+


I have been noticing a ton of latest crashes over the previous few weeks coming into AppStoreConnect referring to LinearGradient which I’ve imported from react-native-linear-gradient

These crash logs ONLY have iOS 17+ so I’m guessing it has one thing to do with a change that occurred within the improve, however do not actually care a lot about that change, I simply need to know the way to repair it in my app and forestall the crash.

This is a simplified reproducible model of my element, a bar which animates from the left to the appropriate, which runs high-quality on iOS 16 and beneath however crashes on 17+ with no logs within the terminal

import React, { useState, useEffect } from 'react';
import { View, Animated } from 'react-native';
import LinearGradient from 'react-native-linear-gradient';

const AnimatedGradient = ({ credit score = 0 }) => {
  const [barWidth, setBarWidth] = useState(1);
  const place = new Animated.Worth(0);

  useEffect(() => {
    Animated.timing(place, {
      toValue: credit score,
      length: 1000,
      useNativeDriver: false,
    }).begin();
  }, [credit]);

  const animatedWidth = place.interpolate({
    inputRange: [0, 1],
    outputRange: [0, barWidth],
  });

  return (
    <View onLayout={(occasion) => setBarWidth(occasion.nativeEvent.structure.width)}>
      <Animated.View fashion={{ width: animatedWidth }}>
        <LinearGradient
          colours={['blue', 'darkblue']}
          begin={{ x: 0, y: 0 }}
          finish={{ x: 1, y: 0 }}
          fashion={{ top: 10 }}
        />
      </Animated.View>
    </View>
  );
};

export default AnimatedGradient;



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments