标签: react-native-android

ToolbarAndroid 未在 React Native 中显示

我正在学习react-native编程,使用这个https://facebook.github.io/react-native/docs/toolbarandroid.html创建工具栏,但在我的情况下它没有被显示。我无法理解我到底在做什么错误。

任何人都可以帮助我。

 import React, { Component } from 'react';
 import { AppRegistry, Text, View, TextInput, TouchableOpacity, ToolbarAndroid } from 'react-native';
 import { ToolBar } from 'react-native-material-design';

 class LoginComponent extends Component {
   render() {
     return (
          <View style={{flex: 1, flexDirection: 'column', margin:10}}>

            <ToolbarAndroid title="Login" titleColor="black"/>

            <TextInput style={{height: 40, borderColor:'gray', borderWidth: .5}}
                placeholder="Email address" underlineColorAndroid='transparent'/>

            <TextInput style={{height: 40, borderColor:'gray', borderWidth: .5}}
                placeholder="Password" secureTextEntry={true} underlineColorAndroid='transparent'/>

            <TouchableOpacity style={{ height: 40, marginTop: 10 , backgroundColor: '#2E8B57'}}>
                <Text style={{color: 'white', textAlign: 'center', …
Run Code Online (Sandbox Code Playgroud)

android react-native react-native-android

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

如何在扩展 Application 或 ReactContextBaseJavaModule 的类中获取 Activity?

如何在 MainApplication 中获取和注入 Activity?我有一个外部库,需要我将活动作为参数传递。这个答案建议我在需要当前活动的部分使用 getCurrentActivity() 方法,但它已从 ReactContextBaseJavaModule 类中删除。有没有其他方法可以做到这一点?如何传递在下面的代码中使用了“this”关键字的活动?谢谢..

package com.bluetoothioexample;

import android.app.Application;
import android.util.Log;

import com.facebook.react.bridge.ReactContextBaseJavaModule;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;

import java.util.Arrays;
import java.util.List;

import com.subsite.bluetoothio.BluetoothIOPackage;
import com.oblador.vectoricons.VectorIconsPackage;

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    protected boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new BluetoothIOPackage(this), //<- How pass the activity
                                        // from ReactApplication ? …
Run Code Online (Sandbox Code Playgroud)

android react-native react-native-android

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

如何在反应原生android中设置视频启动画面

我正在开发示例应用程序,但我想要视频启动画面(在此视频持续时间为 8 秒),实际上我正在设置启动画面页面,但现在我想设置为视频启动画面。

splashPage.js 文件

这是我的代码。从'react-native-video'导入视频;

//import Main from './main';
import LoginScreen from './App/Components/login.js';
class SplashPage extends Component {

componentWillMount () {
        var navigator = this.props.navigator;
        setTimeout (() => {

          navigator.replace({
                component: LoginScreen,
                 // <-- This is the View you go to
            });
        }, 5000);     //<-- Time until it jumps to "MainView"
    }
    render () {
        return (
            <View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>

               <View>{StatusBar.setBackgroundColor('black', true)}</View>
               <Video source={require('./images/splashVideo.mp4')}
                     style={{position: 'absolute',
                             top: 0,
                             left: 0,
                             right: 0,
                             bottom: 0,
                             opacity: …
Run Code Online (Sandbox Code Playgroud)

react-native react-native-android

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

是否可以将渐变颜色用于带有 react-native 的 android 状态栏?

我正在尝试使用 react-native 为 android 状态栏设置渐变颜色。但是 setBackgroundColor 正在获取颜色字符串。

状态栏颜色可以使用渐变色吗?

react-native react-native-android

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

无法将 android React Native 应用程序连接到 localHost .NET api

我有一个 React Native 应用程序,它只需要登录并随后使用返回的 access_token 获取数据。我试图通过连接到在 localHost:50968 上运行的本地托管 .NET api 来调试错误。这返回

    TypeError: Network request failed
Run Code Online (Sandbox Code Playgroud)

我已经在manifext.xml 中启用了互联网权限。大多数谷歌搜索一直在说我需要将 localHost:50968 更改为我的 IP 地址。这是迄今为止使用 '192.168.0.2:50968/token 最接近的,但以下是响应。

    { type: 'default',
status: 400,
ok: false,
statusText: undefined,
headers: { map: { 'content-length': [ '334'
        ],
connection: [ 'close'
        ],
date: [ 'Thu,
            10 Aug201703: 19: 14 GMT'
        ],
server: [ 'Microsoft-HTTPAPI/2.0'
        ],
'content-type': [ 'text/html; charset=us-ascii'
        ]
    }
}, url: 'http: //192.168.0.2:50968/token',
 _bodyInit: 
 '<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">\r\n
<HTML>

<HEAD>
    <TITLE>Bad Request</TITLE>\r\n
    <META HTTP-EQUIV="Content-Type" Content="text/html; …
Run Code Online (Sandbox Code Playgroud)

.net localhost visual-studio react-native react-native-android

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

react-native TouchableNativeFeedback onPress 不起作用

我创建了一个组合组件来将 TouchableNativeFeedback 组合到 wrapperComponent。

export default function withFeedback2(
    WrappedComponent
) {
    return class extends BaseComponent {
        constructor(props) {
            super(props);
        }

        render() {
            return (
                <View>
                    <TouchableNativeFeedback
                        onPress={() => this.props.onContainerViewPress()}

                    >
                        <WrappedComponent {...this.props} />
                    </TouchableNativeFeedback>
                    {/* <TouchableOpacity
                        onPress={this.props.onContainerViewPress ? () => this.props.onContainerViewPress() : null}

 >
                        <WrappedComponent {...this.props} />
                    </TouchableOpacity> */}
                </View>
            );
        }
    };
}
Run Code Online (Sandbox Code Playgroud)

但是TochableNativeFeedback 的 OnPress事件没有触发。而 OnPress 事件被正确触发,并且如果 wrappercomponent 包装在 TouchableOpacity 下,则调用 wrappercomponent 的onContainerViewPress道具。

我正在 Android 平台上对此进行测试。

react-native react-native-android touchableopacity react-navigation touchablewithoutfeedback

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

如何在本机状态下保存一个信号播放器 ID

我是本机反应的新手,我正在使用一个信号进行通知。我从OneSignal.configure();这里得到了一个信号用户玩家 ID,并通过遵循我已经完成的代码但是我只能在控制台上看到的玩家 ID。我正在使用setState保存状态,但它显示错误setState is not a function。如何获取该玩家 ID 以将其保存在状态中。

代码:

componentWillMount() {
          OneSignal.init("d447e6e2-0c8e-4781-8292-6e77d2e86691");

          OneSignal.configure();
          OneSignal.addEventListener('received', this.onReceived);
          OneSignal.addEventListener('opened', this.onOpened);
          OneSignal.addEventListener('ids', this.onIds);
      }

      componentWillUnmount() {
          OneSignal.removeEventListener('received', this.onReceived);
          OneSignal.removeEventListener('opened', this.onOpened);
          OneSignal.removeEventListener('ids', this.onIds);
      }

      onReceived(notification) {
          console.log("Notification received: ", notification);
      }

      onOpened(openResult) {
        console.log('Message: ', openResult.notification.payload.body);
        console.log('Data: ', openResult.notification.payload.additionalData);
        console.log('isActive: ', openResult.notification.isAppInFocus);
        console.log('openResult: ', openResult);
      }

      onIds(device) {
        console.log('Device info: ', device);
      console.log('player id: ', device.userId);
       this.setState({
            pid: device.userId,
          })
       console.log(this.state.pid);
      }
Run Code Online (Sandbox Code Playgroud)

push-notification reactjs react-native onesignal react-native-android

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

i18n React-Native 意外标记 ';'

我在 IOS 项目中设置了 I18n,现在正在 Android 项目中工作。

我不断收到一个意想不到的令牌';' 错误。

当我注释掉字符串和静态导航选项的导入语句时,错误消失并且构建成功:

import React, { Component } from 'react';
import {
  View,
  Text,
  StyleSheet,
  ImageBackgroud,
  // TextInput
} from 'react-native';
// import {
//   Button
// } from 'react-native-elements';
// import {
//   Spinner
// } from '../components/common';

here --> //import { strings } from '../locales/i18n';

class SignUp extends Component {

  //static navigationOptions = {
 here -->// title: strings('SignUp.title')
  //}

  constructor(props) {
    super(props);
    this.state = {
      email: '',
      password: '',
      loading: false
    }; …
Run Code Online (Sandbox Code Playgroud)

react-native react-native-android

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

避免 TextInput 专注于 React Native Android

以下代码在 iOS 上运行良好

<TextInput pointerEvents={"none"} value={textValue2} onPress={something}></TextInput>

但在 android 上似乎pointerEvents不受支持。

我尝试将TextInputa包裹起来,TouchableOpacity但遗憾的是(尽管合理)在按下时仍会给予它焦点。无论如何,我可以在不触发焦点的情况下检测到新闻吗?我试过的其他道具没有用:

editable={false} selectTextOnFocus={false}

react-native react-native-android

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

我如何在 React Native 中设置选择器的样式

我有这个选择器,我为它设置了 borderColor 和 backgrondColor 但它不起作用,我如何为 Picker.item 设置样式?这是我的代码

 <Picker dataSource={this.state.x}
   style={{borderColor:'red' , backgroundColor:'green'}} // doesn't work 

      >

     {this.state.x.map((value)=><Picker.Item label={value} value={value} />)} 

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

react-native react-native-android

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