标签: react-navigation

如何隐藏特定屏幕上的底部标签栏(react-navigation 3.x)

我使用了 createBottomTabNavigator,但无法隐藏特定屏幕上的底部应用栏

const StackHome = createStackNavigator(
  {
    Home: Home,
    Autor: Autor,
    Publicacion: Publicacion,
    Comentarios: {
      screen: Comentarios,
      navigationOptions:{
        // this should do the work, but it doesn't
        tabBarVisible: false
      }
    }
  }
);
Run Code Online (Sandbox Code Playgroud)

javascript react-native react-navigation

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

为什么具有 onPress={action} 的 navigationOptions => headerLeft 中的按钮不起作用?反应本机

我在 React Native 工作,实际上我正在尝试实现一种自定义侧边菜单以避免 DrawerMenu 实现,我尝试只是在 headerLeft 上添加一个图标,但它不起作用,按下时它没有任何动作。

class HomeScreen extends React.Component {
    static navigationOptions = {
        headerTitle: ('',
            <Image style={{ width: 150, height: 40 }}
                source={require('./images/logo.png')}
            />
        ),
        headerLeft: (
            <TouchableHighlight onPress={this._logout}>
                <Image style={{ width: 40, height: 40 }}
                    source={require('./images/hamburger_icon.png')}
                />
            </TouchableHighlight>
        ),
    }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试将按钮放置在 mapView 中时也是如此。

<View style={{ flex: 1 }}>

    <MapView
        ...
    >
        <Button onPress={this._logout} title="Logout" />
    </MapView>

</View >
Run Code Online (Sandbox Code Playgroud)

但是在视图中实现的相同按钮效果很好。

<View style={{ flex: 1 }}>
     <Button onPress={this._logout} title="Logout" />
    <MapView
        ...
    >
        ...
    </MapView>

</View …
Run Code Online (Sandbox Code Playgroud)

react-native react-navigation

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

createMaterialTopTabNavigator 接受活动背景颜色

这可能不是问这个问题的最佳地点,但我在其他任何地方都找不到真正的答案,如果不可能,我会感到惊讶。

我有一个底部标签导航器,底部有四个标签。最初我createBottomTabNavigator用于底部标签导航。它的风格完美地符合我的要求。像下面的图片:
在此处输入图片说明

问题是(在此 GitHub 问题中引用:https : //github.com/react-navigation/react-navigation/issues/4146和此 GitHub 问题:https : //github.com/react-navigation/react-navigation /issues/4236 )createBottomTabNavigator不再支持屏幕动画。所以我按照第一个问题的建议和实施做了createMaterialTopTabNavigator。它的风格几乎完美。这是创建的样式:
在此处输入图片说明

正如您所看到的,我的其他样式使活动文本和活动白色有效,但对于活动选项卡背景颜色,没有任何效果。

这是我的相关代码:

const tabConfigs = {
  tabBarPosition: 'bottom',
  tabBarOptions: {
    inactiveTintColor: '#425563',
    activeTintColor: '#fff',
    activeBackgroundColor: '#ff6900',
    indicatorStyle: {
      display: 'none',
    },
    showIcon: true,
    tabStyle: {
      width: '100%',
    },
    labelStyle: {
      fontSize: 11,
      fontWeight: 'bold',
      marginBottom: 5,
    },
    style: {
      backgroundColor: 'rgba(255, 255, 255, 0.95)',
      height: 55,
      width: '100%',
      borderTopWidth: 0,
      position: 'absolute',
      bottom: 0,
      left: 0, …
Run Code Online (Sandbox Code Playgroud)

javascript react-native react-navigation

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

将套接字传递给组件

这是App.jsReact Native 0.59 应用程序的。

import React, {Component} from 'react';
import { createStackNavigator, createAppContainer } from 'react-navigation';
import Event from './src/components/event/Event.js';
import Chat from './src/components/chat/Chat.js';
import GLOBAL from "../../lib/global";

//socket.io
const socket = io(GLOBAL.BASE_URL, {
  transports: ['websocket'],
  jsonp: false
});

//create the navigator
const navigator = createStackNavigator(
  {
    Event:  Event,
    Chat: {
      screen: Chat,
      
    } 
  }, {
    initialRouteName: "Event"
  }
);

//export it as the root component
export default createAppContainer(navigator); 
Run Code Online (Sandbox Code Playgroud)

socket需要被传递到Chat组件。由于只有 Chat 组件使用socket,我想 …

react-native react-navigation

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

类声明中包含少于 1 种类型 argumanet 的组件

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow
 */

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import { createBottomTabNavigator, createSwitchNavigator, createStackNavigator, createAppContainer } from 'react-navigation';
import Event from './src/components/event/Event.js';
import Chat from './src/components/chat/Chat.js';
import Signup from "./src/components/signup/Signup.js";
import Verif1 from "./src/components/signup/Verif1.js";
import NewEvent from "./src/components/event/Newevent.js";
import EditUser from "./src/components/user/Edituser";
import NewUser from "./src/components/user/Newuser";
import io from 'socket.io-client';
import GLOBAL from "./src/lib/global";
import SplashScreen from "./src/components/splashscreen/SplashScreen";


const instructions = Platform.select({
  ios: …
Run Code Online (Sandbox Code Playgroud)

react-native react-navigation

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

使用钩子以编程方式更新功能组件中的反应导航标题标题

关于反应导航 setParams() 的问题。我在 Reactiflux 上问过,但没有人回答。我正在尝试在函数组件中以编程方式设置标题。

从另一个 Stack Overflow 线程,追溯更新静态标题,像这样,工作:

const Comp = props => { ... };

Comp.navigationOptions = ({ navigation }) => ({
  title: 'Static Title'
});
Run Code Online (Sandbox Code Playgroud)

但是我需要从组件内部访问组件状态,这不起作用:

const Comp =({ navigation }) => {
 const [title, setTitle] = useState('');

 useEffect(() => {
     navigation.setParams({ title });
 }, [title]);

 return ( ... );
}
Run Code Online (Sandbox Code Playgroud)

如果 setParams() 是错误的方法,请赐教

编辑:补充一点,当我console.log(navigation)看到它正在更改navigation.state.params.title为正确的字符串时,但它没有显示为标题。

react-native react-navigation

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

导航到另一个屏幕时,应用程序在 IOS 上冻结 - React Navigation

当我想从 Page1 导航到 Page2 时,当前行为Ios 应用程序冻结

预期行为 我有两个简单的页面,我想从 Page1 转到 Page2 之类的

<Button title = "Go to Page2" onPress={() => this.props.navigation.navigate("Page2")} />
Run Code Online (Sandbox Code Playgroud)

但是在 IOS 模拟器上,当我按下 Button 或 TouchableOpacity 时,应用程序冻结并且无法转到另一个屏幕。实际上第 2 页正在后台加载,但屏幕无法自行更新。

页面1.js

import React, {Component} from 'react';
import {View, Text, Button} from 'react-native';

export default class Page1 extends Component{
    render() {
        return(
            <View>
                <Text>Page 1</Text>
                <Button title = "Go to page 2" onPress={() => this.props.navigation.navigate("Page2")} />
            </View>
        )
    }
}
Run Code Online (Sandbox Code Playgroud)

页面2.js

import React, {Component} from 'react';
import {View, …
Run Code Online (Sandbox Code Playgroud)

ios react-native react-navigation

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

在导航器内反应原生的多个 HeaderRight 按钮

我想在 headerRight 导航选项上显示两个按钮,但是,react-navigation-header-buttons 似乎不允许多个标题按钮组件只使用一个。我想用一个无法工作的组件管理一些状态,因为我在我的导航器文件中/钩子不起作用,因为它不是一个功能组件。

文档

这种方法显然行不通:

headerRight: (
<HeaderButtons HeaderButtonComponent={SoundButton}>
  <Item
    title="Sound" //key
    color="white"
  />
</HeaderButtons>
<HeaderButtons HeaderButtonComponent={ShareButton}>
   <Item
     title="Share" //key
     color="white"
   />
</HeaderButtons>
),
Run Code Online (Sandbox Code Playgroud)

这种方法既不是:

headerRight: (
<HeaderButtons>
      <Item
        title="Sound" //key
        color="white"
        ??? component to call - ButtonElement = ?
      />
      <Item
        title="Share" //key
        color="white"
         ??? component to call - ButtonElement = ?
      />
</HeaderButtons>
)
Run Code Online (Sandbox Code Playgroud)

声音按钮

//React Deps
import React from "react";
import { HeaderButton } from "react-navigation-header-buttons";
import { useDispatch, useSelector …
Run Code Online (Sandbox Code Playgroud)

react-native react-navigation expo

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

null 不是对象(评估“NativeUnimoduleProxy.viewMnagersNames”)

一只忙碌的猫 嗨,我在android中遇到了这个问题。我正在使用 react-native: 0.59.8, @unimodules/core: ^4.0.0, @unimodules/react-native-adapter: ^4.0.0

react-native react-navigation

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

在 StackAction.reset 期间,如何防止 react-navigation 显示过渡动画?

使用 react-navigation-stack 1.10.3,重置 StackActions 将新堆栈加载到位,无需转换。与 react-navigation-stack 2.0.15 相同的代码片段添加了一个平台默认过渡,对于 iOS,它是 SlideFromRightIOS。

如何在 1.10.X 和 2.0.X 上复制之前的行为,其中在堆栈重置时没有转换?

navigation.dispatch(
    StackActions.reset({
        index: 0,
        actions: [
            NavigationActions.navigate({
                routeName: user ? 'Home' : 'Landing',
            }),
        ],
    }),
);
Run Code Online (Sandbox Code Playgroud)

react-native react-navigation expo react-navigation-stack

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