Skip to content

Commit

Permalink
Merge pull request #217 from rydein/master
Browse files Browse the repository at this point in the history
add back, forward, reload method on iOS
  • Loading branch information
slightfoot authored Nov 14, 2018
2 parents 2b646bf + ffe6b33 commit 08ca8f0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
25 changes: 25 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ void main() {
}

class MyApp extends StatelessWidget {
final flutterWebviewPlugin = new FlutterWebviewPlugin();

@override
Widget build(BuildContext context) {
return new MaterialApp(
Expand All @@ -30,6 +32,29 @@ class MyApp extends StatelessWidget {
),
withZoom: true,
withLocalStorage: true,
bottomNavigationBar: BottomAppBar(
child: Row(
children: <Widget>[
IconButton(
icon: const Icon(Icons.arrow_back_ios),
onPressed: () {
flutterWebviewPlugin.goBack();
},
),
IconButton(
icon: const Icon(Icons.arrow_forward_ios),
onPressed: () {
flutterWebviewPlugin.goForward();
},
),
IconButton(
icon: const Icon(Icons.autorenew),
onPressed: () {
flutterWebviewPlugin.reload();
},
),
],
)),
)
},
);
Expand Down
24 changes: 24 additions & 0 deletions ios/Classes/FlutterWebviewPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
} else if ([@"stopLoading" isEqualToString:call.method]) {
[self stopLoading];
result(nil);
} else if ([@"back" isEqualToString:call.method]) {
[self back];
result(nil);
} else if ([@"forward" isEqualToString:call.method]) {
[self forward];
result(nil);
} else if ([@"reload" isEqualToString:call.method]) {
[self reload];
result(nil);
} else {
result(FlutterMethodNotImplemented);
}
Expand Down Expand Up @@ -204,6 +213,21 @@ - (void)stopLoading {
[self.webview stopLoading];
}
}
- (void)back {
if (self.webview != nil) {
[self.webview goBack];
}
}
- (void)forward {
if (self.webview != nil) {
[self.webview goForward];
}
}
- (void)reload {
if (self.webview != nil) {
[self.webview reload];
}
}

#pragma mark -- WkWebView Delegate
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction
Expand Down
3 changes: 0 additions & 3 deletions lib/src/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,12 @@ class FlutterWebviewPlugin {
Future close() => _channel.invokeMethod('close');

/// Reloads the WebView.
/// This is only available on Android for now.
Future reload() => _channel.invokeMethod('reload');

/// Navigates back on the Webview.
/// This is only available on Android for now.
Future goBack() => _channel.invokeMethod('back');

/// Navigates forward on the Webview.
/// This is only available on Android for now.
Future goForward() => _channel.invokeMethod('forward');

// Hides the webview
Expand Down

0 comments on commit 08ca8f0

Please sign in to comment.