Giter Club home page Giter Club logo

Comments (9)

lesnitsky avatar lesnitsky commented on May 28, 2024

@SamBellerose Could you please provide code sample you're getting this error with?

from react-native-webview-messaging.

mosesmc52 avatar mosesmc52 commented on May 28, 2024

Hi,

I'm experiencing a similar issue. Did anyone find a solution?

Moses

from react-native-webview-messaging.

lesnitsky avatar lesnitsky commented on May 28, 2024

@SamBellerose, @mosesmc52 could you please provide more details? I will be really great to assist you

from react-native-webview-messaging.

reggie3 avatar reggie3 commented on May 28, 2024

@R1ZZU, user @PaddyLock is using my react-native-webview-braintree package and has run into the same error on iOS (no problems in in Android). I'm sure it's the same problem that @SamBellerose and @mosesmc52 .

It also looks like the issue is being referenced in the react-native issue thread here facebook/react-native#10865.

Here is the code from my package that experiences the issue.

export default class BraintreePaymentWebview extends React.Component {
  constructor() {
    super();

    this.state = {
      paymentAPIResponse: null,
      showGetNonceActivityIndicator: false,
      showSubmitPaymentActivityIndicator: false
    };
  }
  componentDidMount() {
    // register listeners to listen for events from the html
    // we'll receive a nonce once the requestPaymentMethodComplete is completed
    this.registerMessageListeners();
    console.log('wbvw braintree mounted');
  }

  registerMessageListeners = () => {
    const { messagesChannel } = this.webview;

    messagesChannel.on('RETRIEVE_NONCE_PENDING', event => {
      this.setState({ showGetNonceActivityIndicator: true });
      console.log('RETRIEVE_NONCE_PENDING');
    });

    messagesChannel.on('RETRIEVE_NONCE_FULFILLED', event => {
      console.log('RETRIEVE_NONCE_FULFILLED');
      this.setState({ showGetNonceActivityIndicator: false });
      this.setState({ showSubmitPaymentActivityIndicator: true });
      this.props.nonceObtainedCallback(event.payload.response.nonce);
    });

    messagesChannel.on('RETRIEVE_NONCE_REJECTED', event => {
      console.log('RETRIEVE_NONCE_REJECTED');
      this.setState({ showGetNonceActivityIndicator: false });
    });

    messagesChannel.on('GO_BACK', () => {
      this.props.navigationBackCallback();
    });
  };

  // send the client token to HTML file to begin the braintree flow
  // called when the HTML in the webview is loaded
  sendClientTokenToHTML = () => {
    this.webview.emit('TOKEN_RECEIVED', {
      payload: {
        clientToken: this.props.clientToken,
        options: this.props.options
      }
    });
  };

  // handle purchase responses that parent component sends after making purchase API call
  handlePurchaseResponse = response => {
    console.log('handlePurchaseResponse');
    if (response === 'PAYMENT_SUCCESS') {
      console.log('emitting purchaseSuccess');
      this.setState({ showSubmitPaymentActivityIndicator: false });
      this.webview.emit('PURCHASE_FULFILLED');
    } else {
      this.setState({ showSubmitPaymentActivityIndicator: false });
      this.webview.emit('PURCHASE_REJECTED');
    }
  };

  componentWillReceiveProps = nextProps => {
    console.log({ nextProps });
    if (nextProps.paymentAPIResponse !== this.state.paymentAPIResponse) {
      console.log(nextProps.paymentAPIResponse);
      this.setState({ paymentAPIResponse: nextProps.paymentAPIResponse });
      this.handlePurchaseResponse(nextProps.paymentAPIResponse);
    }
  };

  render() {
    return (
      <View
        style={{
          flex: 1,
          backgroundColor: 'green'
        }}
      >
        <View
          style={{
            flex: 1,
            backgroundColor: 'blue'
          }}
        >
          <WebView
            onLoad={this.sendClientTokenToHTML}
            source={require('./dist/index.html')}
            style={{ flex: 1 }}
            ref={component => (this.webview = component)}
          />
        </View>
        {renderIf(this.state.showGetNonceActivityIndicator)(
          <View style={styles.activityOverlayStyle}>
            <View style={styles.activityIndicatorContainer}>
              <ActivityIndicator
                size="large"
                animating={this.state.showGetNonceActivityIndicator}
                color="blue"
              />
            </View>
          </View>
        )}
        {renderIf(this.state.showSubmitPaymentActivityIndicator)(
          <View style={styles.activityOverlayStyle}>
            <View style={styles.activityIndicatorContainer}>
              <ActivityIndicator
                size="large"
                animating={this.state.showSubmitPaymentActivityIndicator}
                color="green"
              />
            </View>
          </View>
        )}
      </View>
    );
  }
}

BraintreePaymentWebview.propTypes = {
  options: PropTypes.object,
  clientToken: PropTypes.string.isRequired,
  paymentAPIResponse: PropTypes.string.isRequired,
  nonceObtainedCallback: PropTypes.func.isRequired,
  navigationBackCallback: PropTypes.func
};

I'll try to do some more investigating to figure out what specific portion of my code initiates the problem.

from react-native-webview-messaging.

lesnitsky avatar lesnitsky commented on May 28, 2024

@reggie3 I will investigate this issue and try to provide appropriate workaround

from react-native-webview-messaging.

reggie3 avatar reggie3 commented on May 28, 2024

Thanks. Let me know if I can help.

from react-native-webview-messaging.

Maximell avatar Maximell commented on May 28, 2024

Also running into this issue - very interested in a resolution.

from react-native-webview-messaging.

lBroth avatar lBroth commented on May 28, 2024

Same issue

from react-native-webview-messaging.

nacho-carnicero avatar nacho-carnicero commented on May 28, 2024

I did a PR for this in #22 , it solved it for me, and it relies on a fix suggested in facebook/react-native#10865. I don't know if this breaks other stuff though.
@R1ZZU @reggie3 @Maximell @lBroth can you test to check if it works for you as well and it is not breaking anything?

from react-native-webview-messaging.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.