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

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

阅读 462
1 个回答

参考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;
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进