Skip to content

Commit

Permalink
fix iOS13 strange behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
dequan1331 committed Jun 11, 2019
1 parent 2400a5f commit d9be0df
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion HybridPageKit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "HybridPageKit"
s.version = "1.1"
s.version = "1.2"
s.summary = "A high-performance、high-extensibility、easy integration framework for Hybrid content page. Support most content page types of News App."
s.homepage = "https://github.com/dequan1331/HybridPageKit"
s.license = "MIT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ @implementation HPKDefaultWebViewControl
- (void)dealloc {
HPKInfoLog(@"HPKDefaultWebViewControl dealloc with webview contentSize: %@, invalid: %@", NSStringFromCGSize(self.defaultWebView.scrollView.contentSize), @(self.defaultWebView.invalidForReuse));
[[HPKWebViewPool sharedInstance] enqueueWebView:self.defaultWebView];
if(isiOS13Beta1){
[_defaultWebView.scrollView safeRemoveObserver:self keyPath:@"scrollEnabled"];
}
}

- (instancetype)initWithDetailHandler:(HPKPageHandler *)detailHandler
Expand Down Expand Up @@ -120,6 +123,19 @@ - (void)_commonInitWebView {
_defaultWebView = [[HPKWebViewPool sharedInstance] dequeueWebViewWithClass:self.webViewClass webViewHolder:self];
_defaultWebView.frame = CGRectMake(0, 0, self.handler.containerScrollView.frame.size.width, self.handler.containerScrollView.frame.size.height);
_defaultWebView.scrollView.scrollEnabled = NO;

// iOS13Beta1 WKWebView change scrollView scrollEnabled automaticlly in ‘WKWebView _didCommitLayerTree:’
// remove later
if(isiOS13Beta1){
__weak typeof(self)_self = self;
[_defaultWebView.scrollView safeAddObserver:self keyPath:@"scrollEnabled" callback:^(NSObject *oldValue, NSObject *newValue) {
__strong typeof(_self) self = _self;
BOOL scrollEnabled = ((NSNumber *)newValue).boolValue;
if(scrollEnabled){
self.defaultWebView.scrollView.scrollEnabled = NO;
}
}];
}
}

#pragma mark - HPKControllerProtocol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ - (__kindof UIView *)_dequeueViewOfModel:(HPKModel *)model {
if (view) {
if (![view isDescendantOfView:_scrollView]) {
[_scrollView addSubview:view];
[self _bringScrollViewIndicatorToFront];
}
[_onScrollViewComponentViews setObject:view forKey:componentIndex];
} else {
Expand All @@ -344,6 +345,7 @@ - (__kindof UIView *)_dequeueViewOfModel:(HPKModel *)model {
view = [[HPKCommonViewPool sharedInstance] dequeueComponentViewWithClass:viewCls];
[view setComponentViewId:componentIndex];
[_scrollView addSubview:view];
[self _bringScrollViewIndicatorToFront];
[_onScrollViewComponentViews setObject:view forKey:componentIndex];
} else {
[[HPKCommonViewPool sharedInstance] resetVisibleComponentViewState:view];
Expand Down Expand Up @@ -495,6 +497,22 @@ - (void)_scrollToContentOffset:(CGPoint)toContentOffset animated:(BOOL)animated
HPKInfoLog(@"HPKScrollProcessor has scrollto offsety:%@",@(y));
}

- (void)_bringScrollViewIndicatorToFront {
for(__kindof UIView *subView in _scrollView.subviews){
// before iOS13 indicator is UIImageView
Class indicatorClass;
if (@available(iOS 13, *)) {
indicatorClass = NSClassFromString([NSString stringWithFormat:@"%@%@%@",@"_UIScrollViewSc",@"rollIn",@"dicator"]);
}else{
indicatorClass = [UIImageView class];
}
// bring scroll indicator to front
if (indicatorClass && [subView isKindOfClass:indicatorClass]) {
[_scrollView bringSubviewToFront:subView];
}
}
}

#pragma mark -
#pragma mark -
#pragma mark - public
Expand Down
5 changes: 5 additions & 0 deletions HybridPageKit/HybridPageKit/HybridPageKit/Source/_HPKUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@ typedef void (^HPKKVOCallback)(NSObject *oldValue, NSObject *newValue);
- (void)safeRemoveAllObserver;
@end

#pragma mark -

#define isiOS13Beta1 \
([@"13.0" isEqualToString:[[UIDevice currentDevice] systemVersion]])

#endif /* _HPKUtils_h */

0 comments on commit d9be0df

Please sign in to comment.