标签: react-native-android

如何在Android中正确使用React Native中仅有iOS的组件而不会出现错误

我是React Native的新手并测试了PushNotificationIOS.但是checkpermission调用在Android上给我错误.

ExceptionsManager.js:61 Cannot read property 'checkPermissions' of undefined
Run Code Online (Sandbox Code Playgroud)

我猜这是因为我只需要在iOS上使用该组件.如何添加操作系统检查才能在iOS上拨打电话?

这是我的代码:

  componentWillMount: function() {
    //--  need an OS check here??
    PushNotificationIOS.checkPermissions((data)=> {
      console.log("in comp will mount: checking for permission")
      console.log(data.alert)
      console.log(data.badge)
Run Code Online (Sandbox Code Playgroud)

android react-native react-native-android

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

evaluate(this.props.navigator)Undefined不是对象

即使我正确地通过导航器porp,我也会收到此错误.

MySetup就是这样的:主导航器页面 - > FirstView(onBtnPress) - >详细信息

当我在firstView页面中调用this.navigator.push时,我收到错误.

主文件:

import React, { Component, PropTypes } from 'react';

import {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    Navigator
} from 'react-native';

class app extends Component{

    constructor(props) {
        super(props); 
    }


   navigatorRenderScene(route, navigator) {
        return <route.component navigator={navigator}/>

  }
     configureScene() {
    return Navigator.SceneConfigs.VerticalDownSwipeJump;
  }


    render() {

      return (
     <Navigator
        style={styles.container}
        initialRoute= {{component: MainMapView}}
        renderScene={this.navigatorRenderScene}/>
      );
    }
}


const styles = StyleSheet.create({
  container: { flex: 1, flexDirection: 'column', padding: 20 }
});

AppRegistry.registerComponent('app', () => app);
Run Code Online (Sandbox Code Playgroud)

第一部分:

    <ActionButton …
Run Code Online (Sandbox Code Playgroud)

navigator reactjs react-native react-native-android

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

在React Native中如何在会话中存储值?

在React Native中如何在会话中存储值?

我需要在会话中存储登录详细信息(用户名,密码).

你能提出任何想法吗?

react-native react-native-android react-native-ios

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

在TabNavigator中阻止/禁用选项卡 - react-navigation

我有一个TabNavigator,如图所示. 标题图片

我正在使用TabNavigator创建这些选项卡,如下所示.

const Tab_Navigator = TabNavigator({
    First:{
        screen: First,
    },
    Second:{
        screen: Second,
    },
    Third:{
        screen: Third,
    },
Run Code Online (Sandbox Code Playgroud)

现在我想阻止/禁用"第二"和"第三"选项卡.它应该是可见的,但是人们不应该导航到它们.

我尝试阻止这些显示,如我所示,但我想我错过了一些东西.我的尝试:

Tab_Navigator.router.getStateForAction = (action, state) => {
if( action.type === NavigationActions.navigate({ routeName: "Second"}) ||
    action.type === NavigationActions.navigate({ routeName: "Third"}))
{
    return null;
}

return Byte.router.getStateForAction(action, state);
Run Code Online (Sandbox Code Playgroud)

};

tabnavigator react-native react-native-android react-native-ios react-navigation

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

带有文本的行在不使用库的情况下进行原生反应

试图复制以下设计但不能.将不胜感激任何帮助.

在此输入图像描述

我尝试过的代码如下所示,但该行会覆盖文本.

<View>
  <View style={{ alignSelf:'center', borderBottomColor:'black', borderBottomWidth:1,height:'50%', width:'90%' }}/>
  <Text style={{ alignSelf:'center', paddingHorizontal:5 }}>Your class</Text>
</View>
Run Code Online (Sandbox Code Playgroud)

jsx react-native react-native-android react-native-ios

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

React Native WebView Android:阿拉伯语文本显示为奇怪的角色

我正在使用React Native WebView来显示文件中的html内容.我使用iOS模拟器测试过,它工作正常.但不知何故,当我测试它在Android模拟器,阿拉伯语的文字没有显示,而不是奇怪的字符,如正确,: ,,ä 正在出现.öü

这是我的代码:

render() {
    const { content } = this.state

    return (
        <View style={style.container}>
            ...

            <WebView 
                source={{ html: content }}
                onMessage={(event) => this.playAudio.call(this, event.nativeEvent.data)} 
            />
        </View>
    )
}

componentDidMount() {
    const { state } = this.props.navigation

    RNFS.readFileAssets(`content/${state.params.item.id}`, 'utf8')
        .then((content) => {
            console.log('content', content)
            this.setState({ ...this.state, content })
        })
        .catch((err) => {
            console.log('error', err.message, err.code)
        })
}
Run Code Online (Sandbox Code Playgroud)

我的package.json:

{
  "name": "doadzikirandroid",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start", …
Run Code Online (Sandbox Code Playgroud)

android-webview react-native react-native-android

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

从导航道具设置初始状态

我正在使用React Navigation在屏幕之间路由.我有一个初始屏幕,其中包含一个FlatList项目的onclick,我路由到一个新的屏幕,同时传递这样的参数.

props.navigation.navigate('Details', {
    id: props.id,
    title: props.title
});
Run Code Online (Sandbox Code Playgroud)

在Details屏幕上,我可以使用以下代码接收它,但如何设置状态,因为它是一个静态函数,我无权访问this.setState().

static navigationOptions = ({navigation}) => {
    const {params} = navigation.state;

    console.log(params);
};
Run Code Online (Sandbox Code Playgroud)

reactjs react-native react-native-android react-native-navigation react-navigation

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

导航('DrawerOpen')不使用createSwitchNavigator和createStackNavigator

请检查这个世博小吃.

我有一个用于登录和未登录状态的switch-navigator.

当用户登录时,切换器加载一个DrawerNavigator加载Screen1并加载侧边栏(SideBar.js)的contentComponent

在里面,Screen1我正在调用菜单汉堡按钮this.props.navigation.navigate('DrawerOpen');的onPress事件.但它没有打开抽屉.我在做什么呢

react-native react-native-android native-base

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

如何在react-native中获取文件的绝对路径?

我正在寻找react-native中的文件选择器,该选择器返回我选择的文件的绝对路径。我目前正在使用react-native-document-picker,但它以的格式提供了相对路径content://com.android.providers.media.documents/document/......。当我要压缩视频文件时,像react-native-ffmpeg和react-native-video-processing这样的库都需要文件的绝对路径。

react-native react-native-android

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

任务':react-native-gesture-handler:compileDebugJavaWithJavac'的执行失败

我通过gradle.properties在androidRN 0.59项目的下面添加2行来解决与AndroidX相关的不兼容问题。

android.useAndroidX=true
android.enableJetifier=true
Run Code Online (Sandbox Code Playgroud)

现在与run-android相关的另一个错误react-native-gesture-handler。然后,我yarn remove目前react-native-gesture-handler的1.2.0并将其添加回。新版本是1.3.0。这是错误:

> Task :react-native-gesture-handler:compileDebugJavaWithJavac
C:\D\code\js\emps_app\node_modules\react-native-gesture-handler\android\src\main\java\com\swmansion\gesturehandler\react\RNGestureHandlerEvent.java:3: error: package android.support.v4.util does not exist
import android.support.v4.util.Pools;
                              ^
C:\D\code\js\emps_app\node_modules\react-native-gesture-handler\android\src\main\java\com\swmansion\gesturehandler\react\RNGestureHandlerEvent.java:19: error: package Pools does not exist
  private static final Pools.SynchronizedPool<RNGestureHandlerEvent> EVENTS_POOL =
                            ^
C:\D\code\js\emps_app\node_modules\react-native-gesture-handler\android\src\main\java\com\swmansion\gesturehandler\react\RNGestureHandlerStateChangeEvent.java:3: error: package android.support.v4.util does not exist
import android.support.v4.util.Pools;
                              ^
C:\D\code\js\emps_app\node_modules\react-native-gesture-handler\android\src\main\java\com\swmansion\gesturehandler\react\RNGestureHandlerStateChangeEvent.java:19: error: package Pools does not exist
  private static final Pools.SynchronizedPool<RNGestureHandlerStateChangeEvent> EVENTS_POOL =
                            ^
C:\D\code\js\emps_app\node_modules\react-native-gesture-handler\android\src\main\java\com\swmansion\gesturehandler\react\RNGestureHandlerEvent.java:20: error: package Pools does not exist …
Run Code Online (Sandbox Code Playgroud)

react-native react-native-android

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