alinz/react-native-webview-bridge

Is this repo officially inactive ?

adkaushik opened this issue · 4 comments

In react native version 0.60, this library does not seem to work, since react native moved webview from the core in to a separate repo.

Are there any plans to upgrade this library aswell?

Move on and migrate to https://github.com/react-native-community/react-native-webview, I have. It has all functionality this library has, + WKWebView on iOS for performance and more. And far more actively developed

@fungilation seem that it's fully compatible except for the method onBridgeMessage should be replaced with onMessage.

@ahmadalfy How to get data from a form if I submit a form offline in react-native-webview. Because webviewbridge return some response offline but does not get any response from react-native-webview.

And when I this library I have one script like this,
export default function submissionScript(formId, previousResponseId = 'none', previousResponseCreated = 'none') {

let string = `<script>
function prepBridge() {
window.ReactNativeWebView.postMessage = function (message) {
var resultDiv = document.getElementById("theForm");
if(message === "responseSaved")
resultDiv.innerHTML = 'Your response has been stored successfully.';
if(message === "cachedResponseSubmitted")
resultDiv.innerHTML = 'Your submission has been submitted.';
}
}
async function readUploadedFileAsBinary(inputFile) {
const temporaryFileReader = new FileReader();

return new Promise((resolve, reject) => {
  temporaryFileReader.onerror = () => {
    temporaryFileReader.abort();
    window.ReactNativeWebView.postMessage(JSON.stringify({ type: error, msg: "A file error occured" }));
  };

  temporaryFileReader.onload = () => {
    resolve(temporaryFileReader.result);
  };
  temporaryFileReader.readAsBinaryString(inputFile);
});

};

async function grabSubmission()
{
let formId = ${formId}, previousResponseId = '${previousResponseId}', previousResponseCreated = '${previousResponseCreated}';
var fileResults = [], fileElementIds = [];
let hasFiles = false, hasSelectLists = false;

prepBridge();

let fileElements = document.querySelectorAll("#theForm input[type=file]");

if(fileElements.length > 0) {
    hasFiles = true;
    for (var i=0; i < fileElements.length; i++) {
        let thisResult = {};
        var fileElementFile = fileElements[i].files[0];
        console.log(fileElements[i].files[0]);
        fileElementIds.push(fileElements[i].id);

        if(fileElementFile) {
            thisResult.contents = await readUploadedFileAsBinary(fileElementFile);
            thisResult.fieldId = fileElements[i].id;
            thisResult.filename = fileElementFile.name;
            fileResults.push(thisResult);
        }
    }
}

if(wFORMS.instances.esignature > 0) {
    var instances = wFORMS.instances.esignature;

    for (var i = 0; i < instances.length; i++) {
        instances[i].exportSignature();
        instances[i].exportInitials();
    }
}

var form = document.getElementById('theForm');
let formData = new FormData(form);
let basic_form_data = [], select_lists = [];

for(var pair of formData.entries()) {
    if(pair[0].indexOf('[]') > 0) {
        hasSelectLists = true;
        select_lists.push({
            id: pair[0].replace("[]", ""),
            value: pair[1]
        });
    }
    else if(!fileElementIds.includes(pair[0]))
        basic_form_data.push({ inputName: pair[0], value: pair[1] });
};

if (WebViewBridge)
  window.ReactNativeWebView.postMessage(JSON.stringify({ type:'response',
  response: { basic_form_data, select_lists, previousResponseId, previousResponseCreated, hasSelectLists, hasFiles, fileResults, formId } }));

}
</script>`;

return string;

}

So this will return the response offline.

@aneena-thomas sorry, no clue