naoufal / react-native-safari-view

A React Native wrapper for Safari View Controller.
https://www.npmjs.com/package/react-native-safari-view
494 stars 110 forks source link

TypeError: Cannot read property 'show' of undefined #62

Closed seclace closed 7 years ago

seclace commented 7 years ago

Hi. I installed this package with npm i --save react-native-safari-view and then use it in my component:

...

import SafariView from 'react-native-safari-view';

...

pressHandler = () => {
  SafariView.show({ url: this.props.webviewUrl })
  .then((bool) => { console.log('available', bool); })
  .then(SafariView.show({
    url: this.props.webviewUrl,
  }))
  .catch(error => {
    console.log('error:', error);
  });
};

...

render() {
  return (
    <View style={styles.root}>
      <TouchableOpacity
        style={{ borderWidth: 1, alignItems: 'center', padding: 20 }}
        onPress={this.pressHandler}>
        <Text>Press</Text>
      </TouchableOpacity>
    </View>
  );
}

And get this error:

TypeError: Cannot read property 'show' of undefined
    at SafariViewManager.ios.js:27
    at tryCallTwo (core.js:45)
    at doResolve (core.js:200)
    at new Promise (core.js:66)
    at Object.show (SafariViewManager.ios.js:26)
    at Object.Cart._this.pressHandler [as onPress] (Cart.js:77)
    at Constructor.touchableHandlePress (TouchableOpacity.js:119)
    at Constructor.proxiedMethod [as touchableHandlePress] (createPrototypeProxy.js:44)
    at Constructor._performSideEffectsForTransition (Touchable.js:715)
    at Constructor.proxiedMethod [as _performSideEffectsForTransition] (createPrototypeProxy.js:44)

I logged the NativeModules object imported from react-native and it has not SafariViewManager property (== undefined). May be I missed something? RN version is 0.31

I ran node node_modules/react-native/local-cli/cli.js link and did't get any effect from this.

seclace commented 7 years ago

I've tested these steps with RN 0.42.3 and it worked fine.

seclace commented 7 years ago

I needed to rebuild.