I have big amount of text data and fragmented in to small parts and saved in to the array (in code its props.frames)
and now I want to animate these fragments as qr code on iterating a list "frames" .
I tried following but it does not work .
- I know there is Animated.loop api but I am not sure how to apply this logic in my case , I mean on each iteration how to refresh qr code value dynamically
- If you do have any suggestions it would be highly appreciated .
import React, {useState, useEffect,useRef } from 'react';
import {View, Animated} from 'react-native';
import QRCode from 'react-native-qrcode-generator';
function QRCodeLoop(props) {
// const [frame, setFrame] = useState(0);
const currentFrameToAnimate = useRef(new Animated.Value(0)).current;
const opacity = useRef(new Animated.Value(0)).current;
const frame = useRef(new Animated.Value(0)).current;
//const [frameIndex, setFrameIndex] = useState(0);
console.log('props.frames length : ' + props.frames.length);
const frames = props.frames;
const size = props.size;
const fps = props.fps;
let _raf;
useEffect(() => {
console.log('QRCodeLoop use effect called ');
let elapsed;
const nextFrame = (frame, frames) => {
frame = (frame + 1) % frames.length;
console.log('nextFrame:', frame);
console.log('frames.length:', frames.length);
return frame;
};
},[frames]);
return (
<>
<View style={{position: 'relative', width: size, height: size}}>
{frames.map((chunk, i) => {
Animated.timing(frame, {
toValue: chunk,
duration: 1000,
useNativeDriver: true
}).start();
return (
<Animated.View
key={i}
style={{position: 'absolute', opacity: 1}}>
<QRCode
value={chunk}
size={size}
bgColor="purple"
fgColor="white"
/>
</Animated.View>
);
})}
</View>
</>
);
}
export default QRCodeLoop;