Skip to content

Commit

Permalink
Update base html
Browse files Browse the repository at this point in the history
  • Loading branch information
gantunesr committed Nov 17, 2022
1 parent 958f0a3 commit 0c3c990
Showing 1 changed file with 49 additions and 42 deletions.
91 changes: 49 additions & 42 deletions app/components/Views/Snaps/content/base.html
Original file line number Diff line number Diff line change
@@ -1,47 +1,54 @@
<!DOCTYPE html>
<html>
<script>
function killSnap(snapId) {
const frame = document.getElementById(snapId);
if (frame) {
frame.parentNode.removeChild(frame);
}
}
<script>
function removeIframe(elementId) {
const frame = document.getElementById(snapId);
if (frame) {
frame.parentNode.removeChild(frame);
}
}

function createIframe(snapId, sourceCode) {

}
function createIframe(snapId, sourceCode) {
const iframe = document.createElement('iframe');
iframe.id = snapId;
iframe.setAttribute('srcdoc', sourceCode);
iframe.setAttribute('sandbox', 'allow-scripts');

window.addEventListener("message", message => {
const { method, snapId, args } = JSON.parse(message.data);
switch (method) {
case 'start_snap':
// create iframe
return;
case 'execute_snap':
const response = document.getElementById(snapId).contentWindow.snap.onRpcRequest(args);
sendDataToReactNativeApp(JSON.stringify(response))
return;
case 'kill_snap':
killSnap(snapId);
return;
}
});
</script>
<body
style="display: flex; justify-content: center; flex-direction: column; align-items: center;"
>
<button
onclick="sendDataToReactNativeApp()"
style="padding: 20; width: 200; font-size: 30; color: white; background-color: #6751ff;"
>
Send data to app
</button>
<div>
<p id="myContent">Basic HTML</p>
<iframe id="snap-1" name="snap-1" src="./iframe1.html"></iframe>
<iframe id="snap-2" name="snap-2" src="./iframe2.html"></iframe>
</div>
</body>
document.body.appendChild(iframe);
}

</html>
window.addEventListener('message', message => {
console.log(message.data);
const { method, snapId, sourceCode, args } = JSON.parse(message.data);
switch (method) {
case 'start_snap':
createIframe(snapId, sourceCode);
return;
case 'execute_snap':
const response = document.getElementById(snapId).contentWindow.snap.onRpcRequest(args);
sendDataToReactNativeApp(JSON.stringify(response))
return;
case 'kill_snap':
removeIframe(snapId);
return;
default:
return;
}
});
</script>
<body
style="display: flex; justify-content: center; flex-direction: column; align-items: center;"
>
<button
onclick="sendDataToReactNativeApp('Dummy data')"
style="padding: 20; width: 200; font-size: 30; color: white; background-color: #6751ff;"
>
Send dummy data to app
</button>
<div>
<p id="myContent">Basic HTML</p>
<iframe id="snap-1" name="snap-1" src="./iframe1.html"></iframe>
<iframe id="snap-2" name="snap-2" src="./iframe2.html"></iframe>
</div>
</body>
</html>

0 comments on commit 0c3c990

Please sign in to comment.