diff --git a/node_modules/react-native-keyboard-tracking-view/lib/KeyboardTrackingViewManager.m b/node_modules/react-native-keyboard-tracking-view/lib/KeyboardTrackingViewManager.m index 1333a10..86d3678 100644 --- a/node_modules/react-native-keyboard-tracking-view/lib/KeyboardTrackingViewManager.m +++ b/node_modules/react-native-keyboard-tracking-view/lib/KeyboardTrackingViewManager.m @@ -23,7 +23,7 @@ NSUInteger const kInputViewKey = 101010; NSUInteger const kMaxDeferedInitializeAccessoryViews = 15; NSInteger const kTrackingViewNotFoundErrorCode = 1; -NSInteger const kBottomViewHeight = 100; +NSInteger const kBottomViewHeight = 34; typedef NS_ENUM(NSUInteger, KeyboardTrackingScrollBehavior) { KeyboardTrackingScrollBehaviorNone, @@ -40,6 +40,7 @@ @interface KeyboardTrackingView : UIView CGFloat _bottomViewHeight; } +@property (nonatomic) NSMutableDictionary* rctScrollViewsArray; @property (nonatomic, strong) UIScrollView *scrollViewToManage; @property (nonatomic) BOOL scrollIsInverted; @property (nonatomic) BOOL revealKeyboardInteractive; @@ -53,6 +54,13 @@ @interface KeyboardTrackingView : UIView @property (nonatomic) BOOL scrollToFocusedInput; @property (nonatomic) BOOL allowHitsOutsideBounds; +@property (nonatomic) BOOL normalList; +@property (nonatomic) NSString* scrollViewNativeID; +@property (nonatomic) CGFloat initialOffsetY; +@property (nonatomic) BOOL initialOffsetIsSet; +@property (nonatomic, strong) UIView *accessoriesContainer; +@property (nonatomic) NSString* accessoriesContainerID; + @end @interface KeyboardTrackingView () @@ -70,12 +78,17 @@ -(instancetype)init [self addObserver:self forKeyPath:@"bounds" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:NULL]; _inputViewsMap = [NSMapTable weakToWeakObjectsMapTable]; _deferedInitializeAccessoryViewsCount = 0; + _rctScrollViewsArray = [[NSMutableDictionary alloc] init]; _observingInputAccessoryView = [ObservingInputAccessoryView new]; _observingInputAccessoryView.delegate = self; + _initialOffsetY = 0; + _initialOffsetIsSet = NO; + _manageScrollView = YES; _allowHitsOutsideBounds = NO; + _requiresSameParentToManageScrollView = YES; _bottomViewHeight = kBottomViewHeight; @@ -134,7 +147,7 @@ -(void)_swizzleWebViewInputAccessory:(WKWebView*)webview UIView* subview; for (UIView* view in webview.scrollView.subviews) { - if([[view.class description] hasPrefix:@"UIWeb"]) + if([[view.class description] hasPrefix:@"WKWeb"]) { subview = view; } @@ -167,33 +180,32 @@ -(void)layoutSubviews - (void)initializeAccessoryViewsAndHandleInsets { NSArray* allSubviews = [self getBreadthFirstSubviewsForView:[self getRootView]]; - NSMutableArray* rctScrollViewsArray = [NSMutableArray array]; for (UIView* subview in allSubviews) { + if(subview.nativeID) { + NSLog(@"self.accessoriesContainerID %@ %@", self.accessoriesContainerID, subview.nativeID); + } + + if (subview.nativeID && [subview.nativeID isEqualToString:self.accessoriesContainerID]) { + NSLog(@"SuperView ID: %@", subview.nativeID); + _accessoriesContainer = subview; + } + if(_manageScrollView) { if(_scrollViewToManage == nil) { - if(_requiresSameParentToManageScrollView && [subview isKindOfClass:[RCTScrollView class]] && subview.superview == self.superview) - { - _scrollViewToManage = ((RCTScrollView*)subview).scrollView; - } - else if(!_requiresSameParentToManageScrollView && [subview isKindOfClass:[UIScrollView class]]) + if([subview isKindOfClass:[RCTScrollView class]]) { - _scrollViewToManage = (UIScrollView*)subview; - } + RCTScrollView *scrollView = (RCTScrollView*)subview; - if(_scrollViewToManage != nil) - { - _scrollIsInverted = CGAffineTransformEqualToTransform(_scrollViewToManage.superview.transform, CGAffineTransformMakeScale(1, -1)); + if (subview.nativeID && [subview.nativeID isEqualToString:self.scrollViewNativeID]) { + [_rctScrollViewsArray setObject:scrollView forKey:subview.nativeID]; + _scrollViewToManage = scrollView.scrollView; + } } } - - if([subview isKindOfClass:[RCTScrollView class]]) - { - [rctScrollViewsArray addObject:(RCTScrollView*)subview]; - } } if ([subview isKindOfClass:NSClassFromString(@"RCTTextField")]) @@ -242,7 +254,7 @@ - (void)initializeAccessoryViewsAndHandleInsets } } - for (RCTScrollView *scrollView in rctScrollViewsArray) + for (RCTScrollView *scrollView in [_rctScrollViewsArray allValues]) { if(scrollView.scrollView == _scrollViewToManage) { @@ -267,6 +279,21 @@ - (void)initializeAccessoryViewsAndHandleInsets [self addBottomViewIfNecessary]; } +- (void)resetScrollView:(NSString*) scrollViewNativeID { + for (RCTScrollView *scrollView in [_rctScrollViewsArray allValues]) + { + [scrollView removeScrollListener:self]; + } + [_rctScrollViewsArray removeAllObjects]; + _scrollViewToManage = nil; + _scrollViewNativeID = scrollViewNativeID; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [self deferedInitializeAccessoryViewsAndHandleInsets]; + [self scrollToStart]; + }); +} + - (void)setupTextView:(UITextView*)textView { if (textView != nil) @@ -343,7 +370,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N - (void)observingInputAccessoryViewKeyboardWillDisappear:(ObservingInputAccessoryView *)observingInputAccessoryView { - _bottomViewHeight = kBottomViewHeight; + _bottomViewHeight = [self getBottomSafeArea]; [self updateBottomViewFrame]; } @@ -388,32 +415,42 @@ - (void)_updateScrollViewInsets { if(self.scrollViewToManage != nil) { + if (!_initialOffsetIsSet) { + self.initialOffsetY = self.scrollViewToManage.contentOffset.y; + _initialOffsetIsSet = YES; + } + + if (_observingInputAccessoryView.keyboardState != KeyboardStateWillHide && _observingInputAccessoryView.keyboardState != KeyboardStateHidden) { + [self.scrollViewToManage setContentOffset:CGPointMake(self.scrollViewToManage.contentOffset.x, self.initialOffsetY) animated:NO]; + } + UIEdgeInsets insets = self.scrollViewToManage.contentInset; CGFloat bottomSafeArea = [self getBottomSafeArea]; CGFloat bottomInset = MAX(self.bounds.size.height, _observingInputAccessoryView.keyboardHeight + _observingInputAccessoryView.height); CGFloat originalBottomInset = self.scrollIsInverted ? insets.top : insets.bottom; CGPoint originalOffset = self.scrollViewToManage.contentOffset; + CGFloat keyboardHeight = _observingInputAccessoryView.keyboardHeight; - bottomInset += (_observingInputAccessoryView.keyboardHeight == 0 ? bottomSafeArea : 0); + bottomInset += (keyboardHeight == 0 ? bottomSafeArea : 0); if(self.scrollIsInverted) { insets.top = bottomInset; } else { - insets.bottom = bottomInset; + insets.bottom = keyboardHeight; } self.scrollViewToManage.contentInset = insets; if(self.scrollBehavior == KeyboardTrackingScrollBehaviorScrollToBottomInvertedOnly && _scrollIsInverted) { - BOOL fisrtTime = _observingInputAccessoryView.keyboardHeight == 0 && _observingInputAccessoryView.keyboardState == KeyboardStateHidden; + BOOL firstTime = _observingInputAccessoryView.keyboardHeight == 0 && _observingInputAccessoryView.keyboardState == KeyboardStateHidden; BOOL willOpen = _observingInputAccessoryView.keyboardHeight != 0 && _observingInputAccessoryView.keyboardState == KeyboardStateHidden; BOOL isOpen = _observingInputAccessoryView.keyboardHeight != 0 && _observingInputAccessoryView.keyboardState == KeyboardStateShown; - if(fisrtTime || willOpen || (isOpen && !self.isDraggingScrollView)) + if(firstTime || willOpen || (isOpen && !self.isDraggingScrollView)) { - [self.scrollViewToManage setContentOffset:CGPointMake(self.scrollViewToManage.contentOffset.x, -self.scrollViewToManage.contentInset.top) animated:!fisrtTime]; + [self.scrollViewToManage setContentOffset:CGPointMake(self.scrollViewToManage.contentOffset.x, self.scrollViewToManage.contentOffset.y) animated:!firstTime]; } } else if(self.scrollBehavior == KeyboardTrackingScrollBehaviorFixedOffset && !self.isDraggingScrollView) @@ -422,16 +459,15 @@ - (void)_updateScrollViewInsets self.scrollViewToManage.contentOffset = CGPointMake(originalOffset.x, originalOffset.y + insetsDiff); } - insets = self.scrollViewToManage.contentInset; - if(self.scrollIsInverted) - { - insets.top = bottomInset; - } - else - { - insets.bottom = bottomInset; + CGFloat positionY = self.normalList ? 0 : _observingInputAccessoryView.keyboardHeight; + CGRect frame = CGRectMake(self.scrollViewToManage.frame.origin.x, positionY, + self.scrollViewToManage.frame.size.width, self.scrollViewToManage.frame.size.height); + self.scrollViewToManage.frame = frame; + + if (self.accessoriesContainer) { + self.accessoriesContainer.bounds = CGRectMake(self.accessoriesContainer.bounds.origin.x, positionY, + self.accessoriesContainer.bounds.size.width, self.accessoriesContainer.bounds.size.height); } - self.scrollViewToManage.scrollIndicatorInsets = insets; } } @@ -448,7 +484,6 @@ -(void)addBottomViewIfNecessary if (self.addBottomView && _bottomView == nil) { _bottomView = [UIView new]; - _bottomView.backgroundColor = [UIColor whiteColor]; [self addSubview:_bottomView]; [self updateBottomViewFrame]; } @@ -467,6 +502,12 @@ -(void)updateBottomViewFrame } } +-(void)setBottomViewBackgroundColor:(UIColor*) color { + if (_bottomView != nil) { + _bottomView.backgroundColor = color; + } +} + #pragma mark - safe area -(void)safeAreaInsetsDidChange @@ -510,7 +551,7 @@ -(void)updateTransformAndInsets CGFloat accessoryTranslation = MIN(-bottomSafeArea, -_observingInputAccessoryView.keyboardHeight); if (_observingInputAccessoryView.keyboardHeight <= bottomSafeArea) { - _bottomViewHeight = kBottomViewHeight; + _bottomViewHeight = [self getBottomSafeArea]; } else if (_observingInputAccessoryView.keyboardState != KeyboardStateWillHide) { _bottomViewHeight = 0; } @@ -554,6 +595,14 @@ - (void) observingInputAccessoryViewKeyboardWillAppear:(ObservingInputAccessoryV [self performScrollToFocusedInput]; } +- (void)observingInputAccessoryViewKeyboardDidAppear:(ObservingInputAccessoryView *)observingInputAccessoryView { + if (observingInputAccessoryView.keyboardHeight == 0 && self.scrollViewToManage) { + CGRect frame = CGRectMake(self.scrollViewToManage.frame.origin.x, _observingInputAccessoryView.height, + self.scrollViewToManage.frame.size.width, self.scrollViewToManage.frame.size.height); + self.scrollViewToManage.frame = frame; + } +} + #pragma mark - UIScrollViewDelegate methods - (void)scrollViewDidScroll:(UIScrollView *)scrollView @@ -582,6 +631,8 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { self.isDraggingScrollView = YES; + _initialOffsetIsSet = NO; + self.initialOffsetY = scrollView.contentOffset.y; } - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset @@ -592,6 +643,15 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoi - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { self.isDraggingScrollView = NO; + self.initialOffsetY = scrollView.contentOffset.y; +} + +- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView { + self.initialOffsetY = scrollView.contentOffset.y; +} + +- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { + self.initialOffsetY = scrollView.contentOffset.y; } - (CGFloat)getKeyboardHeight @@ -634,6 +694,12 @@ @implementation KeyboardTrackingViewManager RCT_REMAP_VIEW_PROPERTY(addBottomView, addBottomView, BOOL) RCT_REMAP_VIEW_PROPERTY(scrollToFocusedInput, scrollToFocusedInput, BOOL) RCT_REMAP_VIEW_PROPERTY(allowHitsOutsideBounds, allowHitsOutsideBounds, BOOL) +RCT_REMAP_VIEW_PROPERTY(normalList, normalList, BOOL) +RCT_EXPORT_VIEW_PROPERTY(scrollViewNativeID, NSString) +RCT_EXPORT_VIEW_PROPERTY(accessoriesContainerID, NSString) +RCT_CUSTOM_VIEW_PROPERTY(backgroundColor, UIColor, KeyboardTrackingView) { + [view setBottomViewBackgroundColor:[RCTConvert UIColor:json]]; +} + (BOOL)requiresMainQueueSetup { @@ -654,6 +720,20 @@ - (UIView *)view return [[KeyboardTrackingView alloc] init]; } +RCT_EXPORT_METHOD(resetScrollView:(nonnull NSNumber *)reactTag scrollViewNativeID:(NSString*)scrollViewNativeID) { + [self.bridge.uiManager addUIBlock: + ^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { + + KeyboardTrackingView *view = viewRegistry[reactTag]; + if (!view || ![view isKindOfClass:[KeyboardTrackingView class]]) { + RCTLogError(@"Error: cannot find KeyboardTrackingView with tag #%@", reactTag); + return; + } + + [view resetScrollView:scrollViewNativeID]; + }]; +} + RCT_EXPORT_METHOD(getNativeProps:(nonnull NSNumber *)reactTag resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { [self.bridge.uiManager addUIBlock: diff --git a/node_modules/react-native-keyboard-tracking-view/lib/ObservingInputAccessoryView.h b/node_modules/react-native-keyboard-tracking-view/lib/ObservingInputAccessoryView.h index 9b242e8..b500db1 100644 --- a/node_modules/react-native-keyboard-tracking-view/lib/ObservingInputAccessoryView.h +++ b/node_modules/react-native-keyboard-tracking-view/lib/ObservingInputAccessoryView.h @@ -30,6 +30,7 @@ typedef NS_ENUM(NSUInteger, KeyboardState) { - (void)observingInputAccessoryViewKeyboardWillAppear:(ObservingInputAccessoryView*)observingInputAccessoryView keyboardDelta:(CGFloat)delta; - (void)observingInputAccessoryViewKeyboardWillDisappear:(ObservingInputAccessoryView*)observingInputAccessoryView; +- (void)observingInputAccessoryViewKeyboardDidAppear:(ObservingInputAccessoryView*)observingInputAccessoryView; @end diff --git a/node_modules/react-native-keyboard-tracking-view/lib/ObservingInputAccessoryView.m b/node_modules/react-native-keyboard-tracking-view/lib/ObservingInputAccessoryView.m index e472679..dbc5c5e 100644 --- a/node_modules/react-native-keyboard-tracking-view/lib/ObservingInputAccessoryView.m +++ b/node_modules/react-native-keyboard-tracking-view/lib/ObservingInputAccessoryView.m @@ -123,6 +123,11 @@ - (void)_keyboardWillShowNotification:(NSNotification*)notification { [_delegate observingInputAccessoryViewKeyboardWillAppear:self keyboardDelta:_keyboardHeight - _previousKeyboardHeight]; } + + if([_delegate respondsToSelector:@selector(observingInputAccessoryViewKeyboardDidAppear:)]) + { + [_delegate observingInputAccessoryViewKeyboardDidAppear:self]; + } } - (void)_keyboardDidShowNotification:(NSNotification*)notification diff --git a/node_modules/react-native-keyboard-tracking-view/src/KeyboardTrackingView.android.js b/node_modules/react-native-keyboard-tracking-view/src/KeyboardTrackingView.android.js index af15edf..3ba0a3a 100644 --- a/node_modules/react-native-keyboard-tracking-view/src/KeyboardTrackingView.android.js +++ b/node_modules/react-native-keyboard-tracking-view/src/KeyboardTrackingView.android.js @@ -13,5 +13,6 @@ export default class KeyboardTrackingView extends PureComponent { async getNativeProps() { return {trackingViewHeight: 0, keyboardHeight: 0, contentTopInset: 0}; } + resetScrollView() {} scrollToStart() {} } diff --git a/node_modules/react-native-keyboard-tracking-view/src/KeyboardTrackingView.ios.js b/node_modules/react-native-keyboard-tracking-view/src/KeyboardTrackingView.ios.js index 5e2c207..727017c 100644 --- a/node_modules/react-native-keyboard-tracking-view/src/KeyboardTrackingView.ios.js +++ b/node_modules/react-native-keyboard-tracking-view/src/KeyboardTrackingView.ios.js @@ -25,6 +25,12 @@ export default class KeyboardTrackingView extends PureComponent { return {}; } + resetScrollView(scrollViewNativeID) { + if (this.ref && KeyboardTrackingViewManager && KeyboardTrackingViewManager.resetScrollView) { + KeyboardTrackingViewManager.resetScrollView(ReactNative.findNodeHandle(this.ref), scrollViewNativeID); + } + } + scrollToStart() { if (this.ref && KeyboardTrackingViewManager && KeyboardTrackingViewManager.scrollToStart) { KeyboardTrackingViewManager.scrollToStart(ReactNative.findNodeHandle(this.ref));