首页 > 解决方案 > 在加载相同组件但具有不同数据的路由之间反应导航滑动

问题描述

我是反应导航的新手,但我正在尝试制作一个天气应用程序。我希望用户能够保存多个位置,并通过向右滑动切换到不同的位置。所以组件保持不变,但数据发生变化。

有谁知道我怎么能这样工作?我目前正在使用 StackNavigator,但我没有看到任何关于此的文档。(存储的整个位置我已经知道该怎么做,所以它只是关于滑动导航)

标签: reactjsreact-nativereact-native-androidreact-navigation

解决方案


import {Swipeable} from 'react-native-gesture-handler';
 

const Left=()=>{
//call a funcion 
or 
return   // value after a call 
};

const Right =() => {
return (
  <View>
    <Icon
      name="trash-outline"
      size={ms(28)}
      color="black"
      onPress={() => {
        //call a function to change the data.
      }}
    />
  </View>
);


};

<Swipeable
            renderRightActions={() => Right()}
            renderLeftActions={() => Left()}>  
//your component here 
</Swipable>

您可以在组件上左右滑动,并在用户滑动时直接调用该函数或显示一个图标来调用该函数。


推荐阅读