2

I have written a custom right navigation button by following the example given here. However, it seems like the onNavigatorEvent() method does not get called anymore when using a custom component. I even tried passing the onPress event as a prop to my custom component but that comes through as undefined. Is there something I am missing?

This is how I am passing the onPress prop to the function that's creating the button:

Navigation.registerComponent('DoneButton', () => DoneButton);

const DoneButton = ({text, backgroundColor, textColor, onPressAction}) => {
    var containerStyle = [{backgroundColor: backgroundColor, width: 70, height:30, justifyContent:'center', borderRadius:4, shadowColor:'black', shadowOpacity:0.2, shadowRadius:1, shadowOffset:{width:0, height:2}}];            
    return(
        <TouchableOpacity style={containerStyle} onPress={onPressAction}>
            <Text style={[{color:textColor, textAlign: 'center', fontSize:16}]}>
                {text}
            </Text>
        </TouchableOpacity>
    );
}

_renderDoneButton(){
    this.props.navigator.setButtons({
        rightButtons: [
            {
              id:           'Done'
              component:    'DoneButton',
              passProps:    this._DoneButtonProps(),
            }],
    })
}

_DoneButtonProps(){
    return {
        text:               'Done',
        backgroundColor:    'green',
        textColor:          'white',
        onPressAction:      this._doneAction.bind(this)
    }
}

_doneAction(){
    alert('Done');
}
pnizzle
  • 6,243
  • 4
  • 52
  • 81

1 Answers1

2

Since version 1.1.282 you can pass unserializable props to custom buttons, so the onPress method which you are passing should work.

guy.gc
  • 3,359
  • 2
  • 24
  • 39
  • The props are passed fine. Except for the onPress. When debugging every prop seems valid, but the onPressAction is undefined. Can you provide a working example if possible please. – pnizzle Nov 20 '17 at 13:21
  • 1
    What version of RNN do you have? – guy.gc Nov 20 '17 at 13:33
  • I have version 1.1.262. And the props are being passed through as you said. Unless you were referring specifically to the onPress prop. If so then I will upgrade and test again. – pnizzle Nov 20 '17 at 23:37
  • If that version you specified works for passing the onPress prop, then how were the custom buttons responding to touch event before that? Im sure im missing something here... – pnizzle Nov 20 '17 at 23:43