HarmonyOS RN三方组件react-native-pager-view setPageWithoutAnimation()方法带了动画

HarmonyOS
2024-12-25 09:59:56
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

参考demo:

import React from 'react';
import PagerView from 'react-native-pager-view';
import { View, Text, Button } from 'react-native';

const PagerViewTest = () => {
  const pagerRef = React.useRef<PagerView>(null);
  const [index, setIndex] = React.useState(0);
  return (
    <PagerView
  style={{
    flex: 1,
    width: '100%',
    height: 200,
    margin: 10,
    backgroundColor: '#6D8585',
  }}
ref={pagerRef}
initialPage={0}
layoutDirection={'rtl'}
keyboardDismissMode={'on-drag'}
onPageSelected={(e: any) => {
}}>
<View
style={{
  alignItems: 'center',
  padding: 10,
  margin: 10,
  width: '80%',
  height: '80%',
  backgroundColor: '#E6713E',
}}
key="1">

  <Text
style={{
  width: '100%',
  height: 100,
  fontWeight: 'bold',
}}>
First page:({index})
  </Text>

  <Button title='点击跳转setPage' onPress={() => {
  console.warn("setPage");
  pagerRef.current?.setPage(1);
}} />

  </View>
  <View
style={{
  alignItems: 'center',
  padding: 10,
  margin: 10,
  width: '80%',
  height: '80%',
  backgroundColor: '#7A8CF2',
}}
key="2">
  <Text
style={{
  width: '100%',
  height: 100,
  fontWeight: 'bold',
}}>
Second page:({index})
  </Text>

  <Button title='点击跳转setPageWithoutAnimation' onPress={() => {
  console.warn("setPageWithoutAnimation");
  pagerRef.current?.setPageWithoutAnimation(2);
}} />
  </View>
  <View
style={{
  alignItems: 'center',
  padding: 10,
  margin: 10,
  width: '80%',
  height: '80%',
  backgroundColor: '#F28CE9',
}}
key="3">
  <Text
style={{
  width: '100%',
  height: '100%',
  fontWeight: 'bold',
}}>
Third page:({index})
  </Text>
  </View>
  </PagerView>
);
};

export default PagerViewTest;
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
分享
微博
QQ
微信
回复
2024-12-25 12:11:26
相关问题
HarmonyOS react-native-pager-view安装失败
975浏览 • 1回复 待解决
HarmonyOS react-native-pdf三方库问题
859浏览 • 1回复 待解决
react-native三方库使用npm更新
2179浏览 • 1回复 待解决
HarmonyOS RN三方库的适配情况
1376浏览 • 1回复 待解决