Joey Driessen
Joey Driessen

Reputation: 318

Call React-native from custom component

I am fairly new to react-native and I cannot figure out how I can call an event from a custom component. The component I am using is react-native-android-snackbar and I am trying to check if the snackbar is active.

By inspecting the code I have found that there is an event called EVENT_SHOWN. This is exactly what I need but unfortunally I don't know how I can check for this event.

I tried the following:

export default class LoginScreen extends Component {
    constructor(props, context) {
        super(props, context);
        this.state = {username: '', password: '',spinnerVisible:false};
        this._event = this._event.bind(this);
        DeviceEventEmitter.addListener('EVENT_SHOW',this._event);
    }
    _event(event: Event){
        Alert.alert("Event handler","Event handler");
    }

But unfortunally it doesn't work the function doesn't get called when I activate the snackbar.

Hope somebody can help me in the right direction.

Upvotes: 0

Views: 179

Answers (1)

vinayr
vinayr

Reputation: 11234

EVENT_SHOWN is native side of event, the JS event is just shown. So try

Snackbar.addEventListener('shown', this._event);

Upvotes: 1

Related Questions