forked from flutter/plugins
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[webview_flutter] Support for loading progress tracking (flutter#2151)
- Loading branch information
1 parent
4fe6c45
commit 169d4ab
Showing
11 changed files
with
202 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
packages/webview_flutter/ios/Classes/FLTWKProgressionDelegate.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#import <Flutter/Flutter.h> | ||
#import <Foundation/Foundation.h> | ||
#import <WebKit/WebKit.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface FLTWKProgressionDelegate : NSObject | ||
|
||
- (instancetype)initWithWebView:(WKWebView *)webView channel:(FlutterMethodChannel *)channel; | ||
|
||
- (void)stopObservingProgress:(WKWebView *)webView; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
42 changes: 42 additions & 0 deletions
42
packages/webview_flutter/ios/Classes/FLTWKProgressionDelegate.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#import "FLTWKProgressionDelegate.h" | ||
|
||
NSString *const FLTWKEstimatedProgressKeyPath = @"estimatedProgress"; | ||
|
||
@implementation FLTWKProgressionDelegate { | ||
FlutterMethodChannel *_methodChannel; | ||
} | ||
|
||
- (instancetype)initWithWebView:(WKWebView *)webView channel:(FlutterMethodChannel *)channel { | ||
self = [super init]; | ||
if (self) { | ||
_methodChannel = channel; | ||
[webView addObserver:self | ||
forKeyPath:FLTWKEstimatedProgressKeyPath | ||
options:NSKeyValueObservingOptionNew | ||
context:nil]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)stopObservingProgress:(WKWebView *)webView { | ||
[webView removeObserver:self forKeyPath:FLTWKEstimatedProgressKeyPath]; | ||
} | ||
|
||
- (void)observeValueForKeyPath:(NSString *)keyPath | ||
ofObject:(id)object | ||
change:(NSDictionary<NSKeyValueChangeKey, id> *)change | ||
context:(void *)context { | ||
if ([keyPath isEqualToString:FLTWKEstimatedProgressKeyPath]) { | ||
NSNumber *newValue = | ||
change[NSKeyValueChangeNewKey] ?: 0; // newValue is anywhere between 0.0 and 1.0 | ||
int newValueAsInt = [newValue floatValue] * 100; // Anywhere between 0 and 100 | ||
[_methodChannel invokeMethod:@"onProgress" | ||
arguments:@{@"progress" : [NSNumber numberWithInt:newValueAsInt]}]; | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters