我将在我的项目中设计一个抽屉导航。
我通过这个命令安装了它:
npm install @react-navigation/drawer
Run Code Online (Sandbox Code Playgroud)
然后将其导入 App.js
import { createDrawerNavigator } from '@react-navigation/drawer';
import { NavigationContainer } from '@react-navigation/native';
Run Code Online (Sandbox Code Playgroud)
这是我的package.json内容:
"@react-native-community/masked-view": "^0.1.6",
"@react-navigation/drawer": "^5.0.0",
"react": "16.9.0",
"react-native": "0.61.5",
"react-native-gesture-handler": "^1.5.6",
"react-native-reanimated": "^1.7.0",
"react-native-screens": "^2.0.0-beta.1",
"react-native-view-shot": "^3.0.2",
"react-navigation": "^4.1.1",
"react-navigation-stack": "^2.1.0",
Run Code Online (Sandbox Code Playgroud)
这是我的App.js内容:
npm install @react-navigation/drawer
Run Code Online (Sandbox Code Playgroud)
我应该说我已经创建了Login和SecondPage组件并在一个名为的文件中声明了它们root.js
import { createDrawerNavigator } from '@react-navigation/drawer';
import { NavigationContainer } from '@react-navigation/native';
Run Code Online (Sandbox Code Playgroud)
但我收到一个错误(以下屏幕)。
我怎样才能解决这个问题?
索引.js
"@react-native-community/masked-view": "^0.1.6",
"@react-navigation/drawer": "^5.0.0",
"react": "16.9.0",
"react-native": "0.61.5",
"react-native-gesture-handler": "^1.5.6",
"react-native-reanimated": …Run Code Online (Sandbox Code Playgroud) 我知道在类组件中我们以这种方式使用 addListener :
const Animated.Value= new Animated.Value(0);
Animated.Value.addListener((value)=>this.value=value;)
Run Code Online (Sandbox Code Playgroud)
我想知道如何在功能组件中转换 Animated.Value.addListener?第二个问题:我应该将 addListener 放在 useEffect 挂钩中吗?
My app has 5 components (screens), I am using stack navigation version 5, I need the headers for all screens except one screen, I tried to do this via option inside screens like this:
This is my code:
const Stack = createStackNavigator();
const MainStack = () => ({
return(
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="MyTabs" component={MyTabs} />
<Stack.Screen name="Direct" component={Direct} />
<Stack.Screen name="Like" component={Like} />
<Stack.Screen name="Search" component={Search} />
<Stack.Screen name="Home" component={Home} />
</Stack.Navigator>
</NavigationContainer>
)
)}
Run Code Online (Sandbox Code Playgroud) 我已经在我的 React Native 项目中安装了图像选择器,我将在 ios 中链接该包
我运行这些命令:
cd ios && pod install
Run Code Online (Sandbox Code Playgroud)
但我收到这个错误:
pod is not recognized as an internal or external command
Run Code Online (Sandbox Code Playgroud)
我在 Windows 7 中编码,我的 React Native 版本是:“0.61.5”
我怎样才能解决这个问题?
我想为标签导航设置一个图标,但它返回一个错误
这是我的代码:
<Tab.Screen name="Home" component={Home} options={{tabBarIcon:'home'}} />
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
我怎样才能解决这个问题?
我知道如何将图标添加到自定义抽屉导航中,我想知道是否有任何方法可以直接向</Drawer.Navigator>or添加图标<Drawer.Screen/>?
例如这是我的代码:
const MyDrawer=()=>{
const Drawer=createDrawerNavigator();
return(
<NavigationContainer>
<Drawer.Navigator
initialRouteName='Main Page'
>
<Drawer.Screen name='Main Page' component={MainFunc} />
</Drawer.Navigator>
</NavigationContainer>
)
Run Code Online (Sandbox Code Playgroud) 在此代码中,有两个按钮应启用和禁用 ProgressBar。我在两个独立的函数中使用 setInterval 方法来启用 ProgressBar 和clearInterval 来禁用 ProgressBar。第一个按钮可以工作,但第二个按钮(禁用按钮)不起作用您知道我该如何修复它吗?
let [ProgresValue, setProgresValue] = useState(0);
var ID = null;
const StartProgress = () => {
ID = setInterval(() => {
if (ProgresValue <= 1) {
setProgresValue(ProgresValue = ProgresValue + 0.01)}
}, 100);}
const StopProgress = () => {
clearInterval(ID); }
Run Code Online (Sandbox Code Playgroud)
这是返回部分:
return (
<Fragment>
<Text>Progress Bar:{parseFloat((ProgresValue * 100).toFixed(3))}%</Text>
{
(Platform.OS === 'android')
?
(<ProgressBarAndroid
styleAttr='Horizontal'
indeterminate={false}
progress={ProgresValue}
style={{ width: 300 }}
/>)
:
(<ProgressViewIOS
progress={ProgresValue}
/>) }
<TouchableHighlight onPress={StartProgress} style={styles.button}><Text style={{ color: …Run Code Online (Sandbox Code Playgroud) react-native ×7
reactjs ×6
animation ×1
cocoapods ×1
javascript ×1
setinterval ×1
tabnavigator ×1