简体   繁体   English

React Native-如何在IntroSliders之后导航到主体

[英]React Native - How to navigate to main body after IntroSliders

I'm trying to integrate opening app intro sliders to my app, but failing to connect the points to get from the intro to my main app body. 我正在尝试将打开的应用程序简介滑块集成到我的应用程序中,但是无法将要从简介中获得的要点连接到我的主要应用程序主体。

The library i'm using says use 'react-native-app-intro-slider' as such, where an _onDone() function is called to finish the intro and show the 'real' app: 我正在使用的库说这样使用“ react-native-app-intro-slider”,其中_onDone()函数以完成介绍并显示“真实”应用程序:

export default class App extends React.Component {
  _onDone = () => {
    // User finished the introduction. Show "real" app
  }
  render() {
    return (
      <AppIntroSlider
        slides={slides}
        onDone={this._onDone}
      />
    );
  }
}

With the main body of my app (it works when I run it without the intro-slider addition) being this: 应用程序的主体是这样的(在运行该程序时,无需添加Intro-slider即可运行):

render() {
    const contents = collection.map((item, index) => {
                return (
                    <Card key={index}>
                       [[there's stuff here omitted]]
                    </Card>
                )
              });
    return (
                <View style={{flex:1}}>
                  <CardStack>
                   {contents}
                  </CardStack>
                </View>
              );

How can I get this to render after the introslider? 我怎样才能在介绍了内插器之后渲染它? Do I put all that inside the _onDone() function? 是否将所有内容都放在_onDone()函数中? (this doesn't work). (这不起作用)。 Or is there a way write _onDone so that after the component, the regular part of the main app would proceed to go as before? 还是有一种写_onDone的方法,以便在组件之后,主应用的常规部分可以像以前一样继续进行?

export default class App extends React.Component {
  _onDone = () => {
    // Something that lets me pass onto the main part of my app
  }
  render() {
    return (
      <AppIntroSlider
        slides={slides}
        onDone={this._onDone}
      />

// The main body of the app that I want React to get to after the <AppIntroSlider> component.

    const contents = collection.map((item, index) => {
            return (
                <Card key={index}>
                  [[there's stuff here omitted]]
                </Card>
            )
          });
      return (
            <View style={{flex:1}}>
              <CardStack>
                {contents}
              </CardStack>
            </View>
          );
    );
  }
}

If you're not using a navigation library, I would suggest to simply use state: 如果您不使用导航库,建议使用state:

constructor(props) {
  super(props);

  this.state = {
    showRealApp: false
  }
}

_onDone = () => {
  this.setState({ showRealApp: true });
}
render() {
  if (this.state.showRealApp) {
    const contents = collection.map((item, index) => (
      <Card key={index}>
        {...}
      </Card>
    ));
    return (
      <View style={{flex:1}}>
        <CardStack>
          {contents}
        </CardStack>
      </View>
    );
  } else {
    return <AppIntroSlider slides={slides} onDone={this._onDone}/>;
  }
}

You can also consult issue #18 on the react-native-app-intro-slider repo. 您还可以在react-native-app-intro-slider存储库上参考问题#18

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM