Skip to content

Commit 762ce28

Browse files
committed
ZLPConstants (ios): Expose resourceURL, from the bundle.
This points to a location that's part of the built app (i.e., something from `[NSBundle mainBundle]`. We tried using a convenient-looking React Native method, `RCTBundleURLProvider.resourceURLForResourceRoot` [1]. This would be useful if we wanted the files in `ios/webview` as they're served by the packager if the packager is running (i.e., at a URL like http://192.168.0.108:8081/ios/webview/index.html). We don't, particularly. In theory, seeing updates to, e.g., `ios/webview/base.css` without having to rebuild might be nice...but things are set up so that we never change that file manually. Instead, we expect it to be generated for us at build time, as a build phase (that runs `tools/build-webview`). Best not to give any incentive to edit an auto-generated file. Also, that React Native method just won't work nicely for us, it seems. I haven't found a way to use it to express that we want "/ios/webview/index.html" when we're talking to the packager, and just "/webview/index.html" when we're talking to `[NSBundle mainBundle]`. And: Mock `ReactNative.NativeModules.ZLPConstants`, as we probably should have done for `appIdentifierPrefix`. But we're about to remove that, in the next commit. See also discussion [2]. [1]: Added in facebook/react-native@150c522be. [2]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Resource.20URLs/near/924227
1 parent 9a778e5 commit 762ce28

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

ios/ZulipMobile/ZLPConstants.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ - (NSDictionary *)constantsToExport
1717
// In the Info.plist, our custom entry for the App ID
1818
// Prefix (a.k.a. the Team ID plus a dot).
1919
@"appIdentifierPrefix": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppIdentifierPrefix"] ?: [NSNull null],
20+
@"resourceURL": [[[NSBundle mainBundle] resourceURL] absoluteString]
2021
};
2122
}
2223

jest/jestSetup.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@ import mockAsyncStorage from '@react-native-community/async-storage/jest/async-s
2323
//
2424
// [1] https://github.com/facebook/react-native/issues/26579#issuecomment-535244001
2525
// [2] https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/.23M3781.20RN.20v0.2E61.20upgrade/near/931219
26-
jest.mock(
27-
'react-native',
28-
() =>
29-
// Add stuff here
30-
ReactNative,
31-
);
26+
jest.mock('react-native', () => {
27+
ReactNative.NativeModules.ZLPConstants =
28+
// Currently only available on iOS. We don't bother
29+
// conditionalizing on the platform here; if we want to mock
30+
// Platform.OS, we'll likely want to do so per-test. In that
31+
// scenario, we'll need to figure out how to recompute this mock
32+
// with Platform.OS set as desired.
33+
{
34+
resourceURL:
35+
'file:///private/var/containers/Bundle/Application/4DCD4D2B-F745-4C70-AD74-8E5F690CF593/ZulipMobile.app/',
36+
};
37+
return ReactNative;
38+
});
3239

3340
/**
3441
* Boring mocks

0 commit comments

Comments
 (0)