小编par*_*sai的帖子

React-Native:错误设置和从剪贴板获取文本

import React, { useState } from 'react'
import { SafeAreaView, View, Text, TouchableOpacity, StyleSheet } from 'react-native'
import Clipboard from '@react-native-community/clipboard'

const App = () => {
    const [copiedText, setCopiedText] = useState('')

    const copyToClipboard = () => {
        Clipboard.setString('hello world')
    }

    const fetchCopiedText = async () => {
        const text = await Clipboard.getString()
        setCopiedText(text)
    }

    return (
        <SafeAreaView style={{ flex: 1 }}>
            <View style={styles.container}>
                <TouchableOpacity onPress={() => copyToClipboard()}>
                    <Text>Click here to copy to Clipboard</Text>
                </TouchableOpacity>
                <TouchableOpacity onPress={() => fetchCopiedText()}>
                    <Text>View …
Run Code Online (Sandbox Code Playgroud)

react-native

8
推荐指数
4
解决办法
5531
查看次数

react-navigation:从标题中的按钮导航到不同的屏幕

我的标题右侧有一个图标,按下该按钮后,我想导航到不同的屏幕。

我对此进行了大量搜索,但所有解决方案都是针对类组件的,并且没有可用的官方文档。

我正在使用本机版本 0.61.4。

在按下右侧标题中的图标时,我想移动“ProfileScreen”。所有其他导航工作正常。我在“HomeScreen”中有一个按钮可以移动到“ResultsScreen”,但无法从标题转到“ProfileScreen”。

这是我的代码片段

const Stack = createStackNavigator();

const App = () => {
    return (
        <SafeAreaView style={{ flex: 1 }}>
            <NavigationContainer>
                <Stack.Navigator>
                    <Stack.Screen 
                        name="Home" 
                        component={HomeScreen}
                        options={
                            {
                                title: 'Home',
                                headerStyle: {
                                    backgroundColor: '#273469',
                                },
                                headerTintColor: '#EBF2FA',
                                headerRight: () => (
                                    <Icon
                                      onPress={() => navigate('ProfileScreen')}
                                      name="edit"
                                      type="material"
                                    />
                                ),
                            }
                        }
                    />
                    <Stack.Screen 
                        name="ResultsScreen" 
                        component={ResultsScreen}
                    />
                    <Stack.Screen 
                        name="ProfileScreen"
                        component={ProfileScreen}
                    />
                </Stack.Navigator>
            </NavigationContainer>
        </SafeAreaView>
    )
}
Run Code Online (Sandbox Code Playgroud)

react-native react-navigation

5
推荐指数
1
解决办法
2151
查看次数

标签 统计

react-native ×2

react-navigation ×1