Javascript 从React Native中的不同屏幕组件调用应用程序中的函数
我正在开发一个用react native调节钢琴的应用程序。 我有一个App.js和一些用react导航实现的屏幕。问题是,如何从react native中的另一个屏幕组件调用App.js中的函数? 我错过了一些关于react native的东西,我在网上搜索过,但找不到真正有用的东西 App.js代码:Javascript 从React Native中的不同屏幕组件调用应用程序中的函数,javascript,react-native,redux,react-redux,react-navigation,Javascript,React Native,Redux,React Redux,React Navigation,我正在开发一个用react native调节钢琴的应用程序。 我有一个App.js和一些用react导航实现的屏幕。问题是,如何从react native中的另一个屏幕组件调用App.js中的函数? 我错过了一些关于react native的东西,我在网上搜索过,但找不到真正有用的东西 App.js代码: 导出默认类应用程序扩展组件{ ... testFunction=()=>{ ... } render(){ 返回( ( ), }} /> ( ), }} /> ( ), }} /> ); }
导出默认类应用程序扩展组件{
...
testFunction=()=>{
...
}
render(){
返回(
(
),
}}
/>
(
),
}}
/>
(
),
}}
/>
);
}
}
您应该能够通过这样的道具
<Tab.Screen
name="Inharmonicity"
component={(props) => <InharmonicityScreen testFunction={this.testFunction} {...props} />}
options={{
tabBarLabel: "Parameters",
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="cog" color="black" size={26} />
),
}}
/>
}
选择权={{
tabBarLabel:“参数”,
tabBarIcon:({color})=>(
),
}}
/>
记住使用this.testFunction=this.testFunction.bind(this)
然后在desire屏幕中,在构造函数中声明super(props)
后,可以使用props.testFunction()