Skip to content

Commit

Permalink
webview: Prepare to "revive" realm in handleInitialLoad.
Browse files Browse the repository at this point in the history
In an upcoming commit, we'll change the `Auth` type to have a URL
object for the realm. We call `JSON.stringify` on the arguments
passed to `handleInitialLoad`. For the `realm` property, this means
it'll be a string URL, not a URL object. Here, we pick it out in
preparation for "reviving" it back into its URL form in the body of
`handleInitialLoad`.
  • Loading branch information
chrisbobbe committed Sep 21, 2020
1 parent eb8ed32 commit 8b96642
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
55 changes: 54 additions & 1 deletion src/webview/js/generatedEs3.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,55 @@ var compiledWebviewJs = (function (exports) {
return Constructor;
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source), true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
}
return target;
}
var sendMessage = (function (msg) {
window.ReactNativeWebView.postMessage(JSON.stringify(msg));
});
Expand Down Expand Up @@ -610,7 +659,11 @@ var compiledWebviewJs = (function (exports) {
sendScrollMessageIfListShort();
};
var handleInitialLoad = function handleInitialLoad(platformOS, scrollMessageId, auth) {
var handleInitialLoad = function handleInitialLoad(platformOS, scrollMessageId, rawAuth) {
var auth = _objectSpread2(_objectSpread2({}, rawAuth), {}, {
realm: rawAuth.realm
});
if (platformOS === 'ios') {
window.addEventListener('message', handleMessageEvent);
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/webview/js/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,11 @@ const handleUpdateEventContent = (uevent: WebViewUpdateEventContent) => {
export const handleInitialLoad = (
platformOS: string,
scrollMessageId: number | null,
auth: Auth,
// In an upcoming commit, the `realm` part of an `Auth` object will
// be a URL object. It'll be passed here in its stringified form.
rawAuth: {| ...$Diff<Auth, { realm: mixed }>, realm: string |},
) => {
const auth: Auth = { ...rawAuth, realm: rawAuth.realm };
// Since its version 5.x, the `react-native-webview` library dispatches our
// `message` events at `window` on iOS but `document` on Android.
if (platformOS === 'ios') {
Expand Down

0 comments on commit 8b96642

Please sign in to comment.