我有大量的文本数据并分成小部分并保存到数组中(在其 props.frames 的代码中)
,现在我想在迭代列表 "frames" 时将这些片段设置为 qr 代码。我尝试了以下但它不起作用。
- 我知道有 Animated.loop api,但我不确定如何在我的情况下应用此逻辑,我的意思是在每次迭代时如何动态刷新 qr 代码值
- 如果您有任何建议,我们将不胜感激。
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;