vn-verdnaturachat/patches/react-native-keyboard-track...

160 lines
7.1 KiB
Diff

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..4a698c5 100644
--- a/node_modules/react-native-keyboard-tracking-view/lib/KeyboardTrackingViewManager.m
+++ b/node_modules/react-native-keyboard-tracking-view/lib/KeyboardTrackingViewManager.m
@@ -50,6 +50,7 @@ @interface KeyboardTrackingView : UIView
@property (nonatomic) CGFloat originalHeight;
@property (nonatomic) KeyboardTrackingScrollBehavior scrollBehavior;
@property (nonatomic) BOOL addBottomView;
+@property (nonatomic) NSString* bottomViewColor;
@property (nonatomic) BOOL scrollToFocusedInput;
@property (nonatomic) BOOL allowHitsOutsideBounds;
@@ -80,6 +81,7 @@ -(instancetype)init
_bottomViewHeight = kBottomViewHeight;
self.addBottomView = NO;
+ self.bottomViewColor = nil;
self.scrollToFocusedInput = NO;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rctContentDidAppearNotification:) name:RCTContentDidAppearNotification object:nil];
@@ -171,6 +173,7 @@ - (void)initializeAccessoryViewsAndHandleInsets
for (UIView* subview in allSubviews)
{
+ NSString* className = NSStringFromClass([subview class]);
if(_manageScrollView)
{
if(_scrollViewToManage == nil)
@@ -196,7 +199,7 @@ - (void)initializeAccessoryViewsAndHandleInsets
}
}
- if ([subview isKindOfClass:NSClassFromString(@"RCTTextField")])
+ if ([className isEqualToString:@"RCTTextField"])
{
UITextField *textField = nil;
Ivar backedTextInputIvar = class_getInstanceVariable([subview class], "_backedTextInput");
@@ -210,15 +213,15 @@ - (void)initializeAccessoryViewsAndHandleInsets
}
[self setupTextField:textField];
}
- else if ([subview isKindOfClass:NSClassFromString(@"RCTUITextField")] && [subview isKindOfClass:[UITextField class]])
+ else if ([className isEqualToString:@"RCTUITextField"])
{
[self setupTextField:(UITextField*)subview];
}
- else if ([subview isKindOfClass:NSClassFromString(@"RCTMultilineTextInputView")])
+ else if ([className isEqualToString:@"RCTMultilineTextInputView"])
{
[self setupTextView:[subview valueForKey:@"_backedTextInputView"]];
}
- else if ([subview isKindOfClass:NSClassFromString(@"RCTTextView")])
+ else if ([className isEqualToString:@"RCTTextView"])
{
UITextView *textView = nil;
Ivar backedTextInputIvar = class_getInstanceVariable([subview class], "_backedTextInput");
@@ -232,7 +235,7 @@ - (void)initializeAccessoryViewsAndHandleInsets
}
[self setupTextView:textView];
}
- else if ([subview isKindOfClass:NSClassFromString(@"RCTUITextView")] && [subview isKindOfClass:[UITextView class]])
+ else if ([className isEqualToString:@"RCTUITextView"])
{
[self setupTextView:(UITextView*)subview];
}
@@ -267,6 +270,22 @@ - (void)initializeAccessoryViewsAndHandleInsets
[self addBottomViewIfNecessary];
}
+- (void)resetTracking
+{
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+ [self deferedInitializeAccessoryViewsAndHandleInsets];
+ });
+}
+
+-(UIColor *)colorFromHexString:(NSString *)hexString
+{
+ unsigned rgbValue = 0;
+ NSScanner *scanner = [NSScanner scannerWithString:hexString];
+ [scanner setScanLocation:1]; // bypass '#' character
+ [scanner scanHexInt:&rgbValue];
+ return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0];
+}
+
- (void)setupTextView:(UITextView*)textView
{
if (textView != nil)
@@ -448,7 +467,14 @@ -(void)addBottomViewIfNecessary
if (self.addBottomView && _bottomView == nil)
{
_bottomView = [UIView new];
- _bottomView.backgroundColor = [UIColor whiteColor];
+ if (self.bottomViewColor)
+ {
+ _bottomView.backgroundColor = [self colorFromHexString:self.bottomViewColor];
+ }
+ else
+ {
+ _bottomView.backgroundColor = [UIColor whiteColor];
+ }
[self addSubview:_bottomView];
[self updateBottomViewFrame];
}
@@ -632,6 +658,7 @@ @implementation KeyboardTrackingViewManager
RCT_REMAP_VIEW_PROPERTY(manageScrollView, manageScrollView, BOOL)
RCT_REMAP_VIEW_PROPERTY(requiresSameParentToManageScrollView, requiresSameParentToManageScrollView, BOOL)
RCT_REMAP_VIEW_PROPERTY(addBottomView, addBottomView, BOOL)
+RCT_REMAP_VIEW_PROPERTY(bottomViewColor, bottomViewColor, NSString)
RCT_REMAP_VIEW_PROPERTY(scrollToFocusedInput, scrollToFocusedInput, BOOL)
RCT_REMAP_VIEW_PROPERTY(allowHitsOutsideBounds, allowHitsOutsideBounds, BOOL)
@@ -688,6 +715,21 @@ - (UIView *)view
}];
}
+RCT_EXPORT_METHOD(resetTracking:(nonnull NSNumber *)reactTag)
+{
+ [self.bridge.uiManager addUIBlock:
+ ^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, KeyboardTrackingView *> *viewRegistry) {
+
+ KeyboardTrackingView *view = viewRegistry[reactTag];
+ if (!view || ![view isKindOfClass:[KeyboardTrackingView class]]) {
+ RCTLogError(@"Error: cannot find KeyboardTrackingView with tag #%@", reactTag);
+ return;
+ }
+
+ [view resetTracking];
+ }];
+}
+
#pragma mark - helper methods
-(void)rejectPromise:(RCTPromiseRejectBlock)reject withErrorMessage:(NSString*)errorMessage errorCode:(NSInteger)errorCode
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..1e1bd35 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
@@ -14,4 +14,5 @@ export default class KeyboardTrackingView extends PureComponent {
return {trackingViewHeight: 0, keyboardHeight: 0, contentTopInset: 0};
}
scrollToStart() {}
+ resetTracking() {}
}
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..43bc252 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
@@ -30,4 +30,10 @@ export default class KeyboardTrackingView extends PureComponent {
KeyboardTrackingViewManager.scrollToStart(ReactNative.findNodeHandle(this.ref));
}
}
+
+ resetTracking() {
+ if (this.ref && KeyboardTrackingViewManager && KeyboardTrackingViewManager.resetTracking) {
+ KeyboardTrackingViewManager.resetTracking(ReactNative.findNodeHandle(this.ref));
+ }
+ }
}