Skip to content

Commit b0d03f7

Browse files
committed
ios preload
1 parent fa3c70b commit b0d03f7

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

ios/ExpofpViewManager.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@ @interface RCT_EXTERN_MODULE(ExpofpViewManager, RCTViewManager)
44

55
RCT_EXPORT_VIEW_PROPERTY(settings, NSDictionary)
66

7+
// Add preload method export
8+
RCT_EXTERN_METHOD(preload:(NSString *)url
9+
resolver:(RCTPromiseResolveBlock)resolve
10+
rejecter:(RCTPromiseRejectBlock)reject)
11+
712
@end

ios/ExpofpViewManager.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ class ExpofpViewManager: RCTViewManager {
1818
@objc override static func requiresMainQueueSetup() -> Bool {
1919
return true
2020
}
21+
22+
@objc func preload(_ url: NSString,
23+
resolver resolve: @escaping RCTPromiseResolveBlock,
24+
rejecter reject: @escaping RCTPromiseRejectBlock) {
25+
DispatchQueue.main.async {
26+
SharedFplanView.preload(url as String, settings: Settings())
27+
resolve(nil)
28+
}
29+
}
2130
}
2231

2332
class ExpoFPViewProxy: UIView {

src/index.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
UIManager,
44
Platform,
55
type ViewStyle,
6+
NativeModules,
67
} from 'react-native';
78

89
const LINKING_ERROR =
@@ -24,9 +25,28 @@ type ExpofpProps = {
2425

2526
const ComponentName = 'ExpofpView';
2627

28+
// Add native module interface
29+
interface ExpofpModule {
30+
preload(url: string): Promise<void>;
31+
}
32+
33+
const ExpofpModule = NativeModules.ExpofpModule as ExpofpModule;
34+
2735
export const ExpofpView =
2836
UIManager.getViewManagerConfig(ComponentName) != null
2937
? requireNativeComponent<ExpofpProps>(ComponentName)
3038
: () => {
3139
throw new Error(LINKING_ERROR);
3240
};
41+
42+
// Add preload function
43+
export const preload = async (url: string): Promise<void> => {
44+
if (!UIManager.getViewManagerConfig(ComponentName)) {
45+
throw new Error(LINKING_ERROR);
46+
}
47+
return UIManager.dispatchViewManagerCommand(
48+
ComponentName,
49+
'preload',
50+
[url]
51+
);
52+
};

0 commit comments

Comments
 (0)