Search code examples
javascriptreact-nativenavigator-ios

Navigate back in NavigatorIOS react native


I am testing a NavigatorIOS in my react native project. the issue is when i press the buttons to navigate from a component to an other there is no problem but when I try to go back with the button in title bar which NavigatorIOS produced, I get this error: "Unsupported top level event "topScroll" dispatched".

I use react-native-cli = 2.0.1 and react-native = 0.56.0

NOTE: everything is okay when i press "Go back" button in Support component.

here is my code:

The App Component:

import React, { Component } from "react";
import { View, NavigatorIOS } from "react-native";

import { NavigationApp } from "./src/components/index.js";

export default class App extends Component {
  render() {
    return (
      <NavigatorIOS
        style={{ flex: 1 }}
        initialRoute={{
          title: "Navigation app",
          component: NavigationApp
        }}
      />
    );
  }
}

The NavigationApp Component:

import React, { Component } from "react";
import { Text, View, Button, NavigatorIOS } from "react-native";
import { Support } from "./index.js";

class NavigationApp extends Component {
  navigateToSupport = () => {
    this.props.navigator.push({
      title: "Support",
      component: Support
    });
  };

  render() {
    const { containerStyle } = styles;
    return (
      <View style={containerStyle}>
        <Button
          title="Go to support page"
          onPress={this.navigateToSupport}
        />
      </View>
    );
  }
}

const styles = {
  containerStyle: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center"
  }
};

export { NavigationApp };

The Support Component:

import React, { Component } from "react";
import { View, Text, Button } from "react-native";

class Support extends Component {
  backAction = () => {
    this.props.navigator.pop();
  };

  render() {
    return (
      <View style={{ flex: 1, justifyContent: "center", alignItems:"center" }}>
        <Text>You are in support page</Text>
        <Button title="Go back" onPress={this.backAction} />
      </View>
    );
  }
}

export { Support };

Solution

  • The workaround would be to wrap your initial component in a ScrollView

    <ScrollView>
      // ... Initial Component code 
    </ScrollView>
    

    It is an open issue, you may follow the leads here