我正在使用底部导航,当我通过滑动从拨号器屏幕导航到联系人屏幕时,当时我想直接打开手机的联系人屏幕。 下面我分享了ContactComponent文件和BottomNavigation文件的代码。 我是 React Native 的新手,所以请帮助我。 提前致谢。
ContactComponent.js
const ContactComponents = ({ navigation }) => {
useEffect(() => {
Linking.openURL("content://com.android.contacts/contacts")
}, []);
}
export default ContactComponents
BottomNavigation.js
const Tab = createMaterialTopTabNavigator();
export default function BottomNavigation() {
return (
<Tab.Navigator
tabBarPosition='bottom'
initialRouteName='Dialer'
screenOptions={{
tabBarLabelPosition: "beside-icon",
//tabBarLabelStyle: { fontWeight: "700", fontSize: 15, color : 'white'},
tabBarIconStyle: { display: "none" },
tabBarStyle :{backgroundColor : bottomTabBarColor},
tabBarIndicatorStyle : {position : 'relative', borderWidth : 2 , borderColor : bottomTabBarIndicatorColor}
}}>
<Tab.Screen
name="Messages"
component={MessageComponent}
options = {{
tabBarLabel: ({focused, color, size}) => (
<Text style={ [styles.textStyle, {color: focused ? focusedLabelColor : unfocusedLableColor , fontWeight : focused ? 'bold' : 'normal' }] }>Messages </Text>
),
}}
/>
<Tab.Screen
name="Last Ones"
component={LastOnesComponent}
options = {{
tabBarLabel: ({focused, color, size}) => (
<Text style={ [styles.textStyle, {color: focused ? focusedLabelColor : unfocusedLableColor , fontWeight : focused ? 'bold' : 'normal' }] }>Last Ones </Text>
),
}}
/>
<Tab.Screen
name="Dialer"
component={Dialpad}
options = {{
tabBarLabel: ({focused, color, size}) => (
<Text style={ [styles.textStyle, {color: focused ? focusedLabelColor : unfocusedLableColor , fontWeight : focused ? 'bold' : 'normal' }] }>Dialer </Text>
),
}}
/>
<Tab.Screen
name="Contacts"
component={ContactComponents}
options = {{
tabBarLabel: ({focused, color, size}) => (
//<View style={focused ? styles.topTabLine : null}>
<Text style={ [styles.textStyle, {color: focused ? focusedLabelColor : unfocusedLableColor , fontWeight : focused ? 'bold' : 'normal' }] }>Contacts </Text>
//</View>
),
}}
/>
</Tab.Navigator> Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
对于 Android,您可以使用
react-native中的本机Linking打开联系人应用程序。const openContacts = () => { if (Platform.OS === 'android') { Linking.openURL('content://com.android.contacts/contacts'); } };现在,如果您想在拨号器屏幕聚焦时打开联系人屏幕,您可以使用
@react-navigation/native中的useFocusEffect挂钩来执行该操作。在您想要导航到联系人应用程序的屏幕中,使用此挂钩,如图所示。
import { useCallback } from 'react'; import { Linking, Platform } from 'react-native'; import { useFocusEffect } from '@react-navigation/native'; . . . useFocusEffect( useCallback(() => { if (Platform.OS === 'android') { Linking.openURL('content://com.android.contacts/contacts'); } }, []) );这是用于实施的小吃