Skip to content

Commit a3565f8

Browse files
committed
Exported methods to react native
1 parent 1fc08a0 commit a3565f8

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

AQWebView/AQWebView.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ - (void)goForward
8484

8585
- (BOOL)canGoBack
8686
{
87-
return [_webView canGoBack];
87+
return _webView.canGoBack;
8888
}
8989

9090
- (BOOL)canGoForward
9191
{
92-
return [_webView canGoForward];
92+
return _webView.canGoForward;
9393
}
9494

9595
- (void)setSource:(NSDictionary *)source

AQWebView/AQWebViewManager.m

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,46 @@ - (UIView *) view
3838
}];
3939
}
4040

41+
RCT_EXPORT_METHOD(navigationState:(nonnull NSNumber *)reactTag callback:(RCTResponseSenderBlock)callback)
42+
{
43+
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, AQWebView *> *viewRegistry) {
44+
AQWebView *view = viewRegistry[reactTag];
45+
if (![view isKindOfClass:[AQWebView class]]) {
46+
RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view);
47+
}
48+
else {
49+
BOOL canGoForward = [view canGoForward];
50+
BOOL canGoBack = [view canGoBack];
51+
NSDictionary *data = @{@"canGoForward": @(canGoForward),
52+
@"canGoBack": @(canGoBack)};
53+
callback(@[[NSNull null], data]);
54+
}
55+
}];
56+
}
57+
58+
RCT_EXPORT_METHOD(goBack:(nonnull NSNumber *)reactTag)
59+
{
60+
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, AQWebView *> *viewRegistry) {
61+
AQWebView *view = viewRegistry[reactTag];
62+
if (![view isKindOfClass:[AQWebView class]]) {
63+
RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view);
64+
}
65+
else {
66+
[view goBack];
67+
}
68+
}];
69+
}
70+
RCT_EXPORT_METHOD(goForward:(nonnull NSNumber *)reactTag)
71+
{
72+
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, AQWebView *> *viewRegistry) {
73+
AQWebView *view = viewRegistry[reactTag];
74+
if (![view isKindOfClass:[AQWebView class]]) {
75+
RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view);
76+
}
77+
else {
78+
[view goForward];
79+
}
80+
}];
81+
}
82+
4183
@end

0 commit comments

Comments
 (0)