小编hel*_*eer的帖子

如何制作"按TabNavigator选项卡时返回初始StackNavigator屏幕"

介绍

就像Facebook,Instagram和任何其他移动应用程序一样,我想实现'回到Stacknavigator中的初始屏幕'

  1. 如果用户按下按钮,
  2. 它会回到第一页.

简单的用例

  1. 见TabNavigator
  2. 转到"Feed"标签
  3. 转到"用户"屏幕
  4. 转到另一个"用户"屏幕
  5. 按主选项卡图标 - 'Feed'}
  6. 返回"Feed"标签//这样您就不会看到"后退"按钮

如果您不理解这个用例,请发表评论,我将为您绘制其状态流程

主TabNavigator上的图标代码.

navigationOptions: ({ navigation }) => ({
      header: null,
      tabBarIcon: ({ focused }) => {
          const { routeName } = navigation.state;
          ....
          return (
              <TochableWithoutFeedback onPress={()=>{navigation.goback(iconName)}> 
              // undefined is not a function when I press the Button 
              // deeper screen. (not getting any error on Main)
                  <Ionicons
                      name={iconName}
                      size={30}
                      style={{ marginBottom: -3 }}
                      color={focused ? Colors.tabIconSelected : Colors.tabIconDefault}
                      />
             <TochableWithoutFeedback>
         );
  },
Run Code Online (Sandbox Code Playgroud)

react-native react-navigation

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

如何在TabNavigator中隐藏TabBar文本?

我正在使用'react-navigation'中的TabNavigator.我想隐藏或删除图标下的文字.

在此输入图像描述

这是TabNavigator的一部分.(我正在使用世博会)

    Camera: {
      screen: CameraScreen,
    },
    Noti: {
      screen: NotificationScreen,
    },
    Menu: {
      screen: MenuStackNavigator,
    },
  },
  {
    navigationOptions: ({ navigation }) => ({
         header: null, <<<
         tabBarIcon: ({ focused }) => {
                     ...
         },
     }),
     header: null, <<<-
     headerMode: 'none',  <<--       
     tabBarComponent: TabBarBottom,
     tabBarPosition: 'bottom',
     animationEnabled: false,
     swipeEnabled: false,
     backBehavior: 'none',
Run Code Online (Sandbox Code Playgroud)

这是CamaraScreen

class CameraScreen extends Component {
  static navigationOptions = {
    title: 'Camera'
  }
Run Code Online (Sandbox Code Playgroud)

react-native react-navigation

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

当我 setState() 时,FlatList 项目不会更新

我正在构建多个选择模式。当用户按下该项目时,该项目应标记为“已检查”。

问题我从 id 数组中添加/删除了 id。当我打开并检查模态时,它没有显示“检查”标志。但是当我再次关闭并打开模态时,它显示“检查”标志。

在此处输入图片说明

为了跟踪所选项目,我在模态组件的状态中定义了这些项目。

  state = {
    selectedSeasonIds: this.props.selectedSeasonIds,
   }
Run Code Online (Sandbox Code Playgroud)

这是我用来在屏幕上显示模态的 react-native-modal

<Modal
      isVisible={isSelectorVisible}
      onBackdropPress = {() => this.props.hideSelector()}>
      <View style={styles.modalContainer}>
          <FlatList
              style={styles.root}
              data={this.props.items}
              ItemSeparatorComponent={this._renderSeparator}
              keyExtractor={this._keyExtractor}
              renderItem={this._renderItemForMultiple}/>
      </View>
</Modal>
Run Code Online (Sandbox Code Playgroud)

这是每个项目的渲染功能

_renderItemForMultiple = ({item}) => {
    return (
      <TouchableOpacity
        style={styles.itemStyle}
        onPress={() => {this._handleMultipleItemPress(item.id)}}>
        <RkText>{item.value}</RkText>
        { this._renderCheck(item.id) }   <<< Here is the problem
      </TouchableOpacity>
    );
  }
Run Code Online (Sandbox Code Playgroud)

当用户单击该项目时,FlatList 的项目调用 _handleMultipleitemPress

  _handleMultipleItemPress = (id) => {
    let { selectionType } = this.props;
    let { selectedSeasonIds, selectedSizeIds, selectedColorIds } = this.state;
    if(selectionType===2) …
Run Code Online (Sandbox Code Playgroud)

javascript react-native react-native-flatlist

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

无法更改本机基本选项卡的高度

标签工作正常.但是我不能<Tabs>像下面的图像那样改变下划线和高度

在此输入图像描述

我正在使用Native-Base来处理标签.但我想不出任何改变其默认高度的方法.

<Tabs initialPage={0}
  tabBarUnderlineStyle={styles.tabBarUnderlineStyle}
  style={{height:40}}
>
  <Tab 
    heading="Following"
    tabStyle={styles.tabStyle}
    activeTabStyle={styles.activeTabStyle}
    activeTextStyle={styles.activeTextStyle}
    textStyle={styles.textStyle}
  >
    <FeedScreen navigation={this.props.navigation}/>
  </Tab>
Run Code Online (Sandbox Code Playgroud)

我应该使用其他导航吗?原生基地很难定制.. :(

更新请求,我分享我的风格

  tabStyle : {
    // backgroundColor: theme.colors.navbar,
    backgroundColor: 'white',
    justifyContent: 'center',
    width: 120,
    height: 40,
  },
  activeTabStyle: {
    backgroundColor: 'white',
    height: 40,
  },
  textStyle: {
    // color: 'white',
    color: "#968D8A"
  },
  activeTextStyle: {
    // color: 'white',
    color: theme.colors.navbar
  },
  tabBarUnderlineStyle: {
    backgroundColor: theme.colors.navbar,
    height: 2
  }
Run Code Online (Sandbox Code Playgroud)

reactjs react-native native-base react-navigation

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

如何禁用全身份验证步骤?(发送验证电子邮件)

我正在使用所有身份验证(所有身份验证休息)进行基本授权/身份验证。默认情况下,当用户注册时,Django all-auth尝试发送验证电子邮件。

如何禁用它以防止其发送验证电子邮件?

django django-allauth django-rest-auth

2
推荐指数
2
解决办法
1846
查看次数

是否可以在没有“ look_up”字段的情况下使用“ RetrieveUpdateAPIView”?

RetrieveUpdateAPIView的url与特定字段一起使用。(例如。/profile/update/<pk>

我正在从HTTP标头中的令牌获取用户帐户,因此很难将用户的pk包含到URL中。

该视图是我的RetrieveUpdateAPIView。

class ProfileRetrieveAndUpdateProfile(generics.RetrieveUpdateAPIView):
    serializer_class = ProfileRetrieveAndUpdateSerializer
    # lookup_field = 'pk'

    def get_queryset(self):
        qs = Profile.objects.all()
        logged_in_user_profile = qs.filter(user=self.request.user)
        return logged_in_user_profile
Run Code Online (Sandbox Code Playgroud)

我应该只使用views.APIView来实现此功能吗?

django http django-views django-rest-framework

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

在 React Native 中像 Instagram 一样显示图像的一部分?

我正在构建相册 React Native 移动应用程序。因为我想将作为宽图像(1)的一部分的方形图像显示为图像(2)。

所以问题是,如何在 React Native 中正确缩放图像的中间?我可以用 StyleSheet(CSS) 来做吗?或者有图书馆吗?

图像(1) - 2048 像素 x 1152 像素 在此处输入图片说明

图像(2) - 1080 像素 x 1080 像素 在此处输入图片说明

css image http reactjs react-native

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

来自FontAwesome的String.fromCharCode(61444)

我正在使用FontAwesome.ttf和/ <p>String.fromCharCode(61444)</p><Text>String.fromCharCode</Text>打印心脏图标.

61444来自哪里??? 我该如何编码或解码?(心脏图标是&#xf004;)

谢谢!

ps如果你想更好地理解,你可以在这里查看确切的代码:https://github.com/akveo/kittenTricks/blob/master/app/assets/icons.js

html font-awesome

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

为什么我的this.props.navigation.setParams无法正常工作?

我将我的整数数组设置为selectedStyleIds。为什么我的this.props.navigaion.setParams无法正常工作?

  _setSelectedStyleIds = (selectedStyleIds) => {
    const action = NavigationActions.setParams({ 
        params: {selectedStyleIds},
        key: 'id-1509842157447-6' <- got this from console
    });
    this.props.navigation.dispatch(action);
    this.props.navigation.setParams({styleIds:selectedStyleIds});
    this.setState({selectedStyleIds});
  }

onCheck = ({selectedStyleIds}) => {
    console.log('onCheck');
    console.log(selectedStyleIds); <- [1,2,3,4,5]
    this.props._setSelectedStyleIds(selectedStyleIds);
    this.setState({selectedStyleIds}); <- working
}



_handleTagStylePress = () => {
    this.props.navigation.navigate('TagStyle', {onCheck: this.onCheck, selectedStyleIds: this.state.selectedStyleIds});
}
Run Code Online (Sandbox Code Playgroud)

在onNavigatioOptions上(仅用于调试)

onPress={() => {
          let {image, text, ..., selectedSeasonIds,
            gender, selectedSizeIds, selectedColorIds, selectedStyleIds,
            brand, ..., base64 } = navigation.state.params;
          console.log('onsave')
          console.log(navigation.state.params.selectedStyleIds) <<-- []  
Run Code Online (Sandbox Code Playgroud)

我已经检查了这些行超过50次,但显然this.props.navigation.setParams({selectedStyleIds});无法正常工作。

其他所有设置状态和参数都没有问题,但只能将selectedStyleIds设置为navigation.state.params

javascript react-native react-navigation

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

无法从Django获取POST数据(从React发送)

我花了几个小时来解决这个问题.问题是我无法发送POST的正文数据.我从服务器得到500错误.

这是我对React Native的HTTP请求(我想我可能有错误的axios请求).http正文可能有问题吗?

export const createCloth = (token, hType, clothObject) => async dispatch => {
  let headers = { 'Authorization': `JWT ${token}`};
  if(hType==1) {
    headers = { 'Authorization': `JWT ${token}`};
  } else if (hType==2) {
    headers = { 'Authorization': `Bearer ${token}`};
  }

  let {image, text, clothType, ... , onlyMe} = clothObject;

  console.log(text); <- printing ok
  console.log(bigType); <- printing ok

  let response = await axios.post(`${ROOT_URL}/clothes/create/`, {

    text, clothType, ..., onlyMe
  }, {headers});

  console.log(response.data); <<< 500 HTTP error
Run Code Online (Sandbox Code Playgroud)

这是我的Backend API的一部分.

class ClothCreateAPIView(APIView): …
Run Code Online (Sandbox Code Playgroud)

javascript django django-views django-rest-framework axios

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