小编cod*_*z18的帖子

如何在React native redux的reducer中向数组添加元素?

如何arr[]在reducer中的redux状态数组中添加元素?我这样做 -

import {ADD_ITEM} from '../Actions/UserActions'
const initialUserState = {
    arr:[]
}

export default function userState(state = initialUserState, action)
{
    console.log(arr);
    switch (action.type)
    {
        case ADD_ITEM: 
            return { 
                      ...state,
                      arr: state.arr.push([action.newItem])
                   }

        default:
            return state
    }
}
Run Code Online (Sandbox Code Playgroud)

react-native redux react-redux

116
推荐指数
5
解决办法
10万
查看次数

当在react-native中使用fetch时,如何获得响应的状态?

我正在为我的反应原生应用程序制作登录页面.当我的用户名和密码有效且无效时,我的api会发送不同的响应.所以我想在一些状态变量中跟踪并保存我的响应状态,然后相应地执行功能.请建议我这样做的方法.

  doSignUp() {
   console.log("inside post api");
   fetch('MyApiUrl', {
      method: 'POST',
      headers: {
                 'Accept': 'application/json',
                 'Content-Type': 'application/json',

                },


      body: JSON.stringify({
      password: this.state.password,
      email:this.state.email,
      name: this.state.firstname,
      last_name :this.state.last_name,
      mobile:this.state.mobile,
      ssn:"2222222"

     })
      }).then((response) => {console.log('response:',response.status);
             response.json()}
        .then((responseData) => {
                                console.log("inside responsejson");
                                console.log('response object:',responseData)
                                console.log('refresh token:',responseData[0].token.refresh_token)
                                console.log('access token:',responseData[0].token.access_token);



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

}

react-native fetch-api

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

在react-native中的图像视图中从相机获取最近点击的图像

我正在我的反应原生应用程序中实现相机.我希望在点击后在同一屏幕上的小图像视图中显示该相机最近拍摄的图像.但我没有得到如何访问最近点击的图像.每当通过手机点击任何新图像时,它都会被赋予一个默认的随机名称,我如何在图像视图的源代码中引用它?请告诉我一些方法.我的代码是

 class Incident extends Component {
    constructor(props)
    {  super(props)

        this.state=  {path:"",show:false,video:Camera.constants.CaptureMode.video,camera:Camera.constants.CaptureMode.camera}    
      }
    render() {
      return (
              <View style={styles.container}>
             <View style={{flex:72}}>
             <Camera
              ref={(cam) => {
               this.camera = cam;
                }}
              style={styles.preview}
               aspect={Camera.constants.Aspect.fill}
              captureMode={this.state.camera}>

          </Camera>

  </View>
  <View style={{flex:8,opacity:0.5,backgroundColor:'black'}}>

    {()=>this.showClickedImage()}

  </View>


  <View style={{flex:10,flexDirection:'row',justifyContent:'space-between',backgroundColor:'#f3396b'}}>
  <TouchableOpacity style={{flex:33,flexDirection:'column', alignItems: 'center',paddingTop:10}}>
  <Image style={styles.icon} source={require('./Images/menu.png')}/>
  <Text>Home</Text>
  </TouchableOpacity>



  <TouchableOpacity style={{flex:34,flexDirection:'column', height:70,alignItems: 'center',borderColor:'#dd1e52',borderWidth:1,paddingTop:5}} 
                               onPress={()=>this.takePicture()}>
  <Image style={{width:50,height:50}} source={require('./Images/capture.png')}/>

  </TouchableOpacity>





  <TouchableOpacity style={{flex:33,flexDirection:'column', alignItems: 'center',paddingTop:10}}>
  <Image style={styles.icon} source={require('./Images/profile.png')}/>
  <Text>Profile</Text>
  </TouchableOpacity>


  </View>
  </View>
);
      }

      showClickedImage()
  { 
        return <View style={{flex:1,height:40,width:40, borderWidth:1,borderColor:'black'}}>
               <Image style={{width:40,height:40}} source= {{uri: …
Run Code Online (Sandbox Code Playgroud)

react-native react-native-camera react-native-android

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

TextInput的borderRadius属性不适用于react-native。

我想在我的本地应用程序中使用舍入的TextInput,但是当我设置其borderRadius属性时,它不起作用。建议我这样做。

    <TextInput  placeholder="Email" style={styles.textInput} />

    textInput:{

    borderColor:'black',
    backgroundColor:'#D3D3D3',
    width:300,
    borderWidth: 1,
    borderStyle: 'solid',
    fontSize:15,
    borderRadius: 25,

    }
Run Code Online (Sandbox Code Playgroud)

react-native

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

如何在我的本机应用程序中仅使用redux persist仅用于一个reducer而不是导航reducer?

我正在使用Redux坚持使用我的商店来减速器.我的应用程序有两个Reducer导航和用户Reducer.我想只保留用户状态,但我必须根据redux persist的这种语法保持两个状态.

          import {persistStore, autoRehydrate} from 'redux-persist'
          const store = createStore(reducer, undefined, autoRehydrate())
          persistStore(store)
Run Code Online (Sandbox Code Playgroud)

我在create store中传递的reducer是combine reducers的对象.

问题: 我遇到的问题是当我退出我的应用程序时,因为导航状态现在也持续存在,我的应用程序打开了我退出应用程序的同一页面.

我在我的应用程序中使用redux进行导航实验,并希望仅保留用户状态.

react-native redux

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

无法读取来自其他应用程序的通知

我想在 android 中读取来自其他应用程序的通知,但我无法这样做。这些是我实现相同的实现。这是我的 MainActivity.java

package com.example.demoapp;

import androidx.appcompat.app.AppCompatActivity;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    TableLayout tab;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tab = (TableLayout)findViewById(R.id.tab);
         LocalBroadcastManager.getInstance(this).registerReceiver(onNotice, new IntentFilter("Msg"));
    }
    private BroadcastReceiver onNotice= new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String pack = intent.getStringExtra("package");
            String title = intent.getStringExtra("title");
            String text = intent.getStringExtra("text");
            TableRow …
Run Code Online (Sandbox Code Playgroud)

notifications android notificationservices

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