Comments (9)
@SamBellerose Could you please provide code sample you're getting this error with?
from react-native-webview-messaging.
Hi,
I'm experiencing a similar issue. Did anyone find a solution?
Moses
from react-native-webview-messaging.
@SamBellerose, @mosesmc52 could you please provide more details? I will be really great to assist you
from react-native-webview-messaging.
@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.
@reggie3 I will investigate this issue and try to provide appropriate workaround
from react-native-webview-messaging.
Thanks. Let me know if I can help.
from react-native-webview-messaging.
Also running into this issue - very interested in a resolution.
from react-native-webview-messaging.
Same issue
from react-native-webview-messaging.
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)
- Unexpected token / in JSON at postion 0 HOT 11
- Android 4.4.4 below, react native cannot call the web side method HOT 2
- Failed to execute 'postMessage' on 'Window': 2 arguments required, but only 1 present HOT 2
- Event call on Android but not on iOS HOT 3
- await connectToRemote() not returning a connection or error HOT 4
- (V1) Cannot run on Android HOT 2
- Android Javascript injection not working. HOT 16
- Is there an example to send data to RN in pure html/js and not generated? HOT 1
- cant debug. missing setWebContentsDebuggingEnabled(true) method HOT 1
- webview messagesChannel not working on event listener callback
- file miss HOT 1
- Migrate to latest react native version
- The input type file does not work in webview. from android
- Doesn't seem to work on iOS 9.3 HOT 3
- react-native bundling fails when `require`-ing a html file HOT 6
- onPermissionRequest HOT 2
- Can you provide a working HTML? HOT 1
- "Module JSTimersExecution is not a registered callable module (calling callTimers)" Error HOT 3
- Migrate expo example to v20 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-webview-messaging.