cain
cain

Reputation: 739

Handle OnPress inside React-Native navigationOptions

I'm stuck in adding save method inside navigationOptions can you please help me to do right way.

static navigationOptions = ({navigation}) => ({
        headerTitle: "Add New Item",
        ...css.header,
        headerRight: <NavViewRight
            onPress={() => this.rightHeaderAction()} />,
    })

Upvotes: 5

Views: 2954

Answers (1)

Alexei Malashkevich
Alexei Malashkevich

Reputation: 1645

Actually it's not clear what exactly you try to do. But seems like you want to call a non-static method inside class from static method.

You referring to this, but this here not means class instance. In order to call something from your class you need to make method static.

Something like this:

class MyScreen extends Component {
    static navigationOptions = ({
        navigation
    }) => ({
        headerTitle: "Add New Item",
        ...css.header,
        headerRight: < NavViewRight
        onPress = {
            () => MyScreen.rightHeaderAction()
        }
        />,
    })

    static rightHeaderAction() {
        // your code here
    }
}

Upvotes: 7

Related Questions