Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 反应本机导航器-屏幕始终为空_Javascript_Ios_React Native_Navigator - Fatal编程技术网

Javascript 反应本机导航器-屏幕始终为空

Javascript 反应本机导航器-屏幕始终为空,javascript,ios,react-native,navigator,Javascript,Ios,React Native,Navigator,我试图按照react本机站点上的示例()来设置我的导航器,但似乎无法使其正常工作。无论我做什么,GoogSignIn场景总是显示为空白,尽管它确实击中了文件中的两个console.log点。我曾尝试在我的应用程序中将起点切换到不同的场景,但同样的事情总是发生。我想这是我在index.ios.js中使用导航器时犯的错误,但我不确定是什么原因。非常感谢您的帮助 index.ios.js 'use strict'; var React = require('react-native'); var Da

我试图按照react本机站点上的示例()来设置我的导航器,但似乎无法使其正常工作。无论我做什么,GoogSignIn场景总是显示为空白,尽管它确实击中了文件中的两个console.log点。我曾尝试在我的应用程序中将起点切换到不同的场景,但同样的事情总是发生。我想这是我在index.ios.js中使用导航器时犯的错误,但我不确定是什么原因。非常感谢您的帮助

index.ios.js

'use strict';
var React = require('react-native');
var DataEntry = require('./app/DataEntry');
var PasswordView = require('./app/PasswordView');
var GoogSignIn = require('./app/GoogSignIn');


var {
    AppRegistry,
    Image,
    StyleSheet,
    Text,
    View,
    Navigator,
    TouchableOpacity,
} = React;

class PasswordRecovery extends React.Component {
  render() {
    return (
      <Navigator
        ref={this._setNavigatorRef}
        style={styles.container}
        initialRoute={{id: 'GoogSignIn', name: 'Index'}}
        renderScene={this.renderScene}
        configureScene={(route) => {
          if (route.sceneConfig) {
            return route.sceneConfig;
          }
          return Navigator.SceneConfigs.FloatFromRight;
        }} />
    );
  }

  renderScene(route, navigator) {
    switch (route.id) {
    case 'GoogSignIn':
      return <GoogSignIn navigator={navigator} />;
    case 'DataEntry':
      return <DataEntry navigator={navigator} />;
    case 'PasswordView':
      return <PasswordView navigator={navigator} />;
    default:
      return this.noRoute(navigator);
  }

  noRoute(navigator) {
    return (
      <View style={{flex: 1, alignItems: 'stretch', justifyContent: 'center'}}>
        <TouchableOpacity style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}
            onPress={() => navigator.pop()}>
          <Text style={{color: 'red', fontWeight: 'bold'}}>ERROR: NO ROUTE DETECTED</Text>
        </TouchableOpacity>
      </View>
    );
  }

  _setNavigatorRef(navigator) {
    if (navigator !== this._navigator) {
      this._navigator = navigator;

      if (navigator) {
        var callback = (event) => {
          console.log(
            `TabBarExample: event ${event.type}`,
            {
              route: JSON.stringify(event.data.route),
              target: event.target,
              type: event.type,
            }
          );
        };
        // Observe focus change events from the owner.
        this._listeners = [
          navigator.navigationContext.addListener('willfocus', callback),
          navigator.navigationContext.addListener('didfocus', callback),
        ];
      }
    }
  }

  componentWillUnmount() {
    this._listeners && this._listeners.forEach(listener => listener.remove());
  }
}

var styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});


AppRegistry.registerComponent('PasswordRecovery', () => PasswordRecovery);
'use strict';

var React = require('react-native');
var { NativeAppEventEmitter } = require('react-native');
var GoogleSignin = require('react-native-google-signin');
var cssVar = require('cssVar');
var { Icon } = require('react-native-icons');

var {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  TouchableOpacity,
  TouchableHighlight,
  PixelRatio,
  Navigator,
} = React;

var NavigationBarRouteMapper = {

  LeftButton: function(route, navigator, index, navState) {
    if (index === 0) {
      return null;
    }

    var previousRoute = navState.routeStack[index - 1];
    return (
      <TouchableOpacity
        onPress={() => navigator.pop()}
        style={styles.navBarLeftButton}>
        <Text style={[styles.navBarText, styles.navBarButtonText]}>
          {previousRoute.title}
        </Text>
      </TouchableOpacity>
    );
  },

  RightButton: function(route, navigator, index, navState) {
    return (
      null
    );
  },

  Title: function(route, navigator, index, navState) {
    return (
      <Text style={[styles.navBarText, styles.navBarTitleText]}>
        GOOGLE SIGN IN
      </Text>
    );
  },

};

class GoogSignin extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      user: null
    };
  }

  componentWillMount() {
var navigator = this.props.navigator;
var callback = (event) => {
  console.log(
    `NavigationBarSample : event ${event.type}`,
    {
      route: JSON.stringify(event.data.route),
      target: event.target,
      type: event.type,
    }
  );
};

// Observe focus change events from this component.
this._listeners = [
  navigator.navigationContext.addListener('willfocus', callback),
  navigator.navigationContext.addListener('didfocus', callback),
];
  }

  componentWillUnmount() {
    this._listeners && this._listeners.forEach(listener => listener.remove());
  }

  componentDidMount() {
    this._configureOauth(
      '105558473349-7usegucirv10bruohtogd0qtuul3kkhn.apps.googleusercontent.com'
    );
  }

  renderScene(route, navigator) {
      console.log("HERE");
      return (
        <View style={styles.container}>
          <TouchableHighlight onPress={() => {this._signIn(); }}>
            <View style={{backgroundColor: '#f44336', flexDirection: 'row'}}>
              <View style={{padding: 12, borderWidth: 1/2, borderColor: 'transparent', borderRightColor: 'white'}}>
                <Icon
                  name='ion|social-googleplus'
                  size={24}
                  color='white'
                  style={{width: 24, height: 24}}
                />
              </View>
              <Text style={{color: 'white', padding: 12, marginTop: 2, fontWeight: 'bold'}}>Sign in with Google</Text>
            </View>
          </TouchableHighlight>
        </View>
      );
  }

  render() {
    return (
      <Navigator
      debugOverlay={false}
      style={styles.container}
      renderScene={this.renderScene}
      navigationBar={
        <Navigator.NavigationBar
          routeMapper={NavigationBarRouteMapper}
          style={styles.navBar}/>
      }/>
    );
  }

  _configureOauth(clientId, scopes=[]) {
    console.log("WE HERE")
    GoogleSignin.configure(clientId, scopes);

    NativeAppEventEmitter.addListener('googleSignInError', (error) => {
      console.log('ERROR signin in', error);
    });

    NativeAppEventEmitter.addListener('googleSignIn', (user) => {
      console.log(user);
      this.setState({user: user});
    });

    return true;
  }

  _signIn() {
    GoogleSignin.signIn();
  }

  _signOut() {
    GoogleSignin.signOut();
    this.setState({user: null});
  }
};

var styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  messageText: {
    fontSize: 17,
    fontWeight: '500',
    padding: 15,
    marginTop: 50,
    marginLeft: 15,
  },
  button: {
    backgroundColor: 'white',
    padding: 15,
    borderBottomWidth: 1 / PixelRatio.get(),
    borderBottomColor: '#CDCDCD',
  },
  buttonText: {
    fontSize: 17,
    fontWeight: '500',
  },
  navBar: {
    backgroundColor: 'white',
  },
  navBarText: {
    fontSize: 16,
    marginVertical: 10,
  },
  navBarTitleText: {
    color: cssVar('fbui-bluegray-60'),
    fontWeight: '500',
    marginVertical: 9,
  },
  navBarLeftButton: {
    paddingLeft: 10,
  },
  navBarRightButton: {
    paddingRight: 10,
  },
  navBarButtonText: {
    color: cssVar('fbui-accent-blue'),
  },
  scene: {
    flex: 1,
    paddingTop: 20,
    backgroundColor: '#EAEAEA',
  },
});



module.exports = GoogSignin;
“严格使用”;
var React=require('React-native');
var DataEntry=require('./app/DataEntry');
var PasswordView=require('./app/PasswordView');
var GOOGSIGN=要求('./应用程序/GOOGSIGN');
变量{
评估学,
形象,,
样式表,
文本,
看法
领航员,
可触摸不透明度,
}=反应;
类密码恢复扩展了React.Component{
render(){
返回(
{
if(路由场景图){
返回路线.sceneConfig;
}
从右侧返回Navigator.sceneconfig.floatfrom;
}} />
);
}
renderScene(路线、导航器){
交换机(route.id){
“GoogSignIn”案例:
返回;
案例“数据输入”:
返回;
大小写“PasswordView”:
返回;
违约:
返回此.noRoute(导航器);
}
诺鲁特(领航员){
返回(
navigator.pop()}>
错误:未检测到路由
);
}
_setNavigatorRef(导航器){
如果(导航器!==此.\u导航器){
这个。_navigator=navigator;
if(导航器){
变量回调=(事件)=>{
console.log(
`TabBarExample:event${event.type}`,
{
路由:JSON.stringify(event.data.route),
target:event.target,
类型:event.type,
}
);
};
//观察所有者的焦点更改事件。
这是。_侦听器=[
navigator.navigationContext.addListener('willfocus',回调),
navigator.navigationContext.addListener('didfocus',回调),
];
}
}
}
组件将卸载(){
this._listeners&&this._listeners.forEach(listener=>listener.remove());
}
}
var styles=StyleSheet.create({
容器:{
弹性:1,
为内容辩护:“中心”,
对齐项目:“居中”,
背景颜色:“#F5FCFF”,
},
欢迎:{
尺寸:20,
textAlign:'中心',
差额:10,
},
说明:{
textAlign:'中心',
颜色:'#333333',
marginBottom:5,
},
});
AppRegistry.registerComponent('PasswordRecovery',()=>PasswordRecovery);
我只是想得到这一切设置,以便我可以显示谷歌登录场景,然后从那里导航。到目前为止,该场景的代码如下:

GoogSignIn.js

'use strict';
var React = require('react-native');
var DataEntry = require('./app/DataEntry');
var PasswordView = require('./app/PasswordView');
var GoogSignIn = require('./app/GoogSignIn');


var {
    AppRegistry,
    Image,
    StyleSheet,
    Text,
    View,
    Navigator,
    TouchableOpacity,
} = React;

class PasswordRecovery extends React.Component {
  render() {
    return (
      <Navigator
        ref={this._setNavigatorRef}
        style={styles.container}
        initialRoute={{id: 'GoogSignIn', name: 'Index'}}
        renderScene={this.renderScene}
        configureScene={(route) => {
          if (route.sceneConfig) {
            return route.sceneConfig;
          }
          return Navigator.SceneConfigs.FloatFromRight;
        }} />
    );
  }

  renderScene(route, navigator) {
    switch (route.id) {
    case 'GoogSignIn':
      return <GoogSignIn navigator={navigator} />;
    case 'DataEntry':
      return <DataEntry navigator={navigator} />;
    case 'PasswordView':
      return <PasswordView navigator={navigator} />;
    default:
      return this.noRoute(navigator);
  }

  noRoute(navigator) {
    return (
      <View style={{flex: 1, alignItems: 'stretch', justifyContent: 'center'}}>
        <TouchableOpacity style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}
            onPress={() => navigator.pop()}>
          <Text style={{color: 'red', fontWeight: 'bold'}}>ERROR: NO ROUTE DETECTED</Text>
        </TouchableOpacity>
      </View>
    );
  }

  _setNavigatorRef(navigator) {
    if (navigator !== this._navigator) {
      this._navigator = navigator;

      if (navigator) {
        var callback = (event) => {
          console.log(
            `TabBarExample: event ${event.type}`,
            {
              route: JSON.stringify(event.data.route),
              target: event.target,
              type: event.type,
            }
          );
        };
        // Observe focus change events from the owner.
        this._listeners = [
          navigator.navigationContext.addListener('willfocus', callback),
          navigator.navigationContext.addListener('didfocus', callback),
        ];
      }
    }
  }

  componentWillUnmount() {
    this._listeners && this._listeners.forEach(listener => listener.remove());
  }
}

var styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});


AppRegistry.registerComponent('PasswordRecovery', () => PasswordRecovery);
'use strict';

var React = require('react-native');
var { NativeAppEventEmitter } = require('react-native');
var GoogleSignin = require('react-native-google-signin');
var cssVar = require('cssVar');
var { Icon } = require('react-native-icons');

var {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  TouchableOpacity,
  TouchableHighlight,
  PixelRatio,
  Navigator,
} = React;

var NavigationBarRouteMapper = {

  LeftButton: function(route, navigator, index, navState) {
    if (index === 0) {
      return null;
    }

    var previousRoute = navState.routeStack[index - 1];
    return (
      <TouchableOpacity
        onPress={() => navigator.pop()}
        style={styles.navBarLeftButton}>
        <Text style={[styles.navBarText, styles.navBarButtonText]}>
          {previousRoute.title}
        </Text>
      </TouchableOpacity>
    );
  },

  RightButton: function(route, navigator, index, navState) {
    return (
      null
    );
  },

  Title: function(route, navigator, index, navState) {
    return (
      <Text style={[styles.navBarText, styles.navBarTitleText]}>
        GOOGLE SIGN IN
      </Text>
    );
  },

};

class GoogSignin extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      user: null
    };
  }

  componentWillMount() {
var navigator = this.props.navigator;
var callback = (event) => {
  console.log(
    `NavigationBarSample : event ${event.type}`,
    {
      route: JSON.stringify(event.data.route),
      target: event.target,
      type: event.type,
    }
  );
};

// Observe focus change events from this component.
this._listeners = [
  navigator.navigationContext.addListener('willfocus', callback),
  navigator.navigationContext.addListener('didfocus', callback),
];
  }

  componentWillUnmount() {
    this._listeners && this._listeners.forEach(listener => listener.remove());
  }

  componentDidMount() {
    this._configureOauth(
      '105558473349-7usegucirv10bruohtogd0qtuul3kkhn.apps.googleusercontent.com'
    );
  }

  renderScene(route, navigator) {
      console.log("HERE");
      return (
        <View style={styles.container}>
          <TouchableHighlight onPress={() => {this._signIn(); }}>
            <View style={{backgroundColor: '#f44336', flexDirection: 'row'}}>
              <View style={{padding: 12, borderWidth: 1/2, borderColor: 'transparent', borderRightColor: 'white'}}>
                <Icon
                  name='ion|social-googleplus'
                  size={24}
                  color='white'
                  style={{width: 24, height: 24}}
                />
              </View>
              <Text style={{color: 'white', padding: 12, marginTop: 2, fontWeight: 'bold'}}>Sign in with Google</Text>
            </View>
          </TouchableHighlight>
        </View>
      );
  }

  render() {
    return (
      <Navigator
      debugOverlay={false}
      style={styles.container}
      renderScene={this.renderScene}
      navigationBar={
        <Navigator.NavigationBar
          routeMapper={NavigationBarRouteMapper}
          style={styles.navBar}/>
      }/>
    );
  }

  _configureOauth(clientId, scopes=[]) {
    console.log("WE HERE")
    GoogleSignin.configure(clientId, scopes);

    NativeAppEventEmitter.addListener('googleSignInError', (error) => {
      console.log('ERROR signin in', error);
    });

    NativeAppEventEmitter.addListener('googleSignIn', (user) => {
      console.log(user);
      this.setState({user: user});
    });

    return true;
  }

  _signIn() {
    GoogleSignin.signIn();
  }

  _signOut() {
    GoogleSignin.signOut();
    this.setState({user: null});
  }
};

var styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  messageText: {
    fontSize: 17,
    fontWeight: '500',
    padding: 15,
    marginTop: 50,
    marginLeft: 15,
  },
  button: {
    backgroundColor: 'white',
    padding: 15,
    borderBottomWidth: 1 / PixelRatio.get(),
    borderBottomColor: '#CDCDCD',
  },
  buttonText: {
    fontSize: 17,
    fontWeight: '500',
  },
  navBar: {
    backgroundColor: 'white',
  },
  navBarText: {
    fontSize: 16,
    marginVertical: 10,
  },
  navBarTitleText: {
    color: cssVar('fbui-bluegray-60'),
    fontWeight: '500',
    marginVertical: 9,
  },
  navBarLeftButton: {
    paddingLeft: 10,
  },
  navBarRightButton: {
    paddingRight: 10,
  },
  navBarButtonText: {
    color: cssVar('fbui-accent-blue'),
  },
  scene: {
    flex: 1,
    paddingTop: 20,
    backgroundColor: '#EAEAEA',
  },
});



module.exports = GoogSignin;
“严格使用”;
var React=require('React-native');
var{nativeAppEventMitter}=require('react-native');
var GoogleSignin=require('react-native-google-signin');
var cssVar=require('cssVar');
var{Icon}=require('react-native-icons');
变量{
评估学,
样式表,
文本,
看法
可触摸不透明度,
触控高光,
像素比率,
领航员,
}=反应;
变量NavigationBarRouteMapper={
LeftButton:功能(路由、导航器、索引、导航状态){
如果(索引==0){
返回null;
}
var-previousRoute=navState.routeStack[index-1];
返回(
navigator.pop()}
style={styles.navBarLeftButton}>
{previousRoute.title}
);
},
右按钮:功能(路线、导航器、索引、导航状态){
返回(
无效的
);
},
标题:功能(路线、导航器、索引、导航状态){
返回(
谷歌登录
);
},
};
类GoogSignin扩展了React.Component{
建造师(道具){
超级(道具);
此.state={
用户:空
};
}
组件willmount(){
var navigator=this.props.navigator;
变量回调=(事件)=>{
console.log(
`NavigationBarSample:event${event.type}`,
{
路由:JSON.stringify(event.data.route),
target:event.target,
类型:event.type,
}
);
};
//观察此组件中的焦点更改事件。
这是。_侦听器=[
navigator.navigationContext.addListener('willfocus',回调),
navigator.navigationContext.addListener('didfocus',回调),
];
}
组件将卸载(){
this._listeners&&this._listeners.forEach(listener=>listener.remove());
}
componentDidMount(){
此。\ u配置了OAuth(
'105558473349-7usegucirv10bruohtogd0qtuul3kkhn.apps.googleusercontent.com'
);
}
renderScene(路线、导航器){
console.log(“此处”);
返回(
{这个。_sign();}}>
使用谷歌登录
);
}
render(){
返回(
);
}
_configureOauth(客户端ID,作用域=[])){
log(“我们在这里”)
GoogleSignin.configure(clientId,scopes);
NativeAppEventMitter.addListener('GoogleSignError',(错误)=>{
console.log('ERROR signin',ERROR);
});
NativeAppEventMitter.addListener('googleSignIn',(用户)=>{
console.log(用户);
this.setState({user:user});
});
返回true;
}
_签名(){
谷歌签名;
}
_签出(){
GoogleSignin.signOut();
this.setState({user:null});
}
};
var styles=StyleSheet.create({
容器:{
弹性:1,
为内容辩护:“中心”,
对齐项目:“居中”,
背景颜色:“#F5FCFF”,
},
messageText:{
尺寸:17,
容重:“500”,
填充:15,
玛金托普:50,
marginLeft:15,
},
按钮:{
背景颜色:“白色”,
填充:15,
borderBottomWidth:1/PixelRatio.get(),
borderBottomColor:“#CDCDCD”,
},
按钮文字:{
尺寸:17,
丰威格