【问题标题】:React Native: Is there way to add icon "share" into my drawer instead the button?React Native:有没有办法在我的抽屉中添加图标“共享”而不是按钮?
【发布时间】:2020-05-20 13:34:28
【问题描述】:

有没有办法将图标“分享”添加到我的抽屉中? 我尝试添加一个图标<Ionicons name="md-share" size={24} color="black" />,它将改为Button。 现在,如果我这样做,我只会看到没有标题的图标,就像我在 settings 中看到的那样


import { shareDb } from '../helpers/shareDb';

const PlacesNavigator = createStackNavigator(
  {
    screen1: WaterQualitySamplesScreen, // FUNCTIONAL COMPONENT.
    screen2: AreasPrototypesScreen, // CLASS COMPONENT.
    screen3: PrototypePointsScreen,
    screen4: ListOfPerformanceRequirementsScreen,
    screen5: ContainersForSampling_1,
    screen6: ContainersForSampling_2,
    screen7: ContainersForSampling_3,
    settings: SettingsScreen,
  },
  {
    mode: 'modal',
    defaultNavigationOptions: {
      headerStyle: {
        // animationEnabled: true,
        backgroundColor: Platform.OS === 'android' ? Colors.primary : '',
      },
      headerTintColor: Platform.OS === 'android' ? 'white' : Colors.primary,
    },
  }
);


const SettingsNavigator = createStackNavigator(
  {
    settings: SettingsScreen,
  },
  {
    navigationOptions: {
      drawerIcon: (drawerConfig) => (
        <Ionicons
          name={Platform.OS === 'android' ? 'md-settings' : 'ios-settings'}
          size={23}
          color={drawerConfig.tintColor}
        />
      ),
    },
  }
);


const MainNavigatopr = createDrawerNavigator(
  {
    'close menu': PlacesNavigator,
    settings: SettingsNavigator,  
  },
  {
    contentComponent: (props) => (
      <SafeAreaView style={styles.container}>
        <View
          style={{
            height: 220,
            alignItems: 'center',
            justifyContent: 'center',
            paddingTop: 60,
            paddingBottom: 20,
          }}
        >
          <Image
            source={require('../assets/drawer_image.png')}
            style={{ width: '100%', height: '100%' }}
            resizeMode="contain"
          />
          <View style={styles.sidebarDivider}></View>
        </View>
        <ScrollView>
          <DrawerItems {...props} />
<Button title="LOG OUT" onPress={() => shareDb()} title="DB-Share" />
        </ScrollView>
      </SafeAreaView>
    ),
  }
);
const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  sidebarDivider: {
    height: 1,
    width: '100%',
    backgroundColor: 'lightgray',
    marginVertical: 10,
  },
});

export default createAppContainer(MainNavigatopr);

【问题讨论】:

    标签: javascript reactjs react-native navigation navigation-drawer


    【解决方案1】:

    你可以为你的问题 1 做这样的事情

    const SettingsNavigator = createStackNavigator(
      {
        settings: SettingsScreen,
      },
      {
        initialRouteName:settings,
        navigationOptions: {
          title: 'Settings',
          style: settingStyle.header, // you can create a different style sheet and import in here
          titleStyle: settingStyle.headerTitle,
          tabBarIcon: ({ tintColor }) => (
            <Image source={settingActive} style={[{ tintColor }]} />
          ),
        } as NavigationBottomTabOptions,
      },
    );
    

    如果您想在活动和非活动时更改选项卡设置

    SettingScreens.navigationOptions = () => {
      const navigationOptions: NavigationBottomTabOptions = {};
      navigationOptions.tabBarLabel = ({ focused }: any) =>
        focused ? (
          <Text style={styles.fontBoldCenter}> Setting</Text>
        ) : (
          <Text style={styles.fontCenter}> Setting</Text>
        );
      navigationOptions.tabBarIcon = ({ focused }) =>
        focused ? (
          <Image source={settingActive} />
        ) : (
          <Image source={settingInactive} />
        );
    
      return navigationOptions;
    };
    

    【讨论】:

    • 你的代码的第 2 部分不是我在我的第 2 部分中的意思。我只想从那里删除关闭设置。你的第 1 部分对我不起作用.. 你能把我的代码和你的更改一起发给我吗?
    • 我的代码的第 2 部分只是为了分享您可以执行的其他设置。这不是您的问题 2 的解决方案。
    • @shira 从抽屉中删除关闭屏幕后,您希望看到的默认屏幕是什么?
    • 你能告诉我我的代码和你的改变吗?我想看看它是否工作
    • screen1 是默认的第一页,但它不应该在抽屉里。在抽屉里我现在只想看到设置屏幕。
    猜你喜欢
    • 1970-01-01
    • 2021-08-23
    • 2020-05-09
    • 1970-01-01
    • 2020-12-12
    • 2015-06-27
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多