Skip to content

Commit

Permalink
Merge pull request #13 from pjbank/fix/fix-webview
Browse files Browse the repository at this point in the history
Fixed deprecated webview
  • Loading branch information
andreluisjunqueira authored Sep 22, 2021
2 parents d60a632 + 23c7e03 commit 9bffcea
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-pjbank-checkout-input",
"version": "1.0.2",
"version": "1.0.3",
"description": "React native input component para checkout transparente utilizando o pjbank",
"main": "src/index.js",
"scripts": {
Expand Down
17 changes: 7 additions & 10 deletions src/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,19 @@ export default (function(){
},'');
}

patchPostMessageFunction = ()=>{
const _patchPostMessageFunction = function() {
var originalPostMessage = window.postMessage;

patchPostMessageFunction = () => {
return `
var originalPostMessage = window.ReactNativeWebView.postMessage;
var patchedPostMessage = function(message, targetOrigin, transfer) {
originalPostMessage(message, targetOrigin, transfer);
};

patchedPostMessage.toString = function() {
return String(Object.hasOwnProperty).replace('hasOwnProperty', 'postMessage');
};
window.postMessage = patchedPostMessage;

};
return '(' + String(_patchPostMessageFunction) + ')();';
true;
`;
}

generateHtmlCode = config => (inputStyle, placeholder) => `
Expand All @@ -37,7 +34,6 @@ export default (function(){
<script type="text/javascript">
superlogica.require("pjbank");
superlogica.pjbank("checkout_transparente","${config.credencial}",${config.homologacao});
function handleChange(token){
if(token){
if(${config.blurOnDone} === true) document.getElementById("cartao").blur();
Expand All @@ -58,8 +54,9 @@ export default (function(){
}
function onChangeInputCartao(text) {
var max = 16;
window.postMessage(JSON.stringify({teste: "aabababa"}))
var max = 16;
if (text.length > max) {
document.getElementById('cartao').value = text.substr(0, max);
return;
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { View, WebView, TextInput } from 'react-native';
import { View } from 'react-native';
import { WebView } from 'react-native-webview';

import fns from './functions';

export const EVENT_TYPE_ON_DATA = 'onData';
Expand Down

0 comments on commit 9bffcea

Please sign in to comment.