hybrid-navigation 2.14.0-rc.4 → 2.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,7 @@ import com.facebook.react.bridge.ReactApplicationContext;
8
8
  import com.facebook.react.uimanager.ViewManager;
9
9
 
10
10
  import java.util.Arrays;
11
+ import java.util.Collections;
11
12
  import java.util.List;
12
13
 
13
14
  public class HybridNavigationPackage implements ReactPackage {
@@ -18,18 +19,14 @@ public class HybridNavigationPackage implements ReactPackage {
18
19
  return Arrays.<NativeModule>asList(
19
20
  new NavigationModule(reactContext, ReactBridgeManager.get()),
20
21
  new GardenModule(reactContext, ReactBridgeManager.get()),
21
- new HBDEventEmitter(reactContext),
22
- new KeyboardInsetsModule(reactContext)
22
+ new HBDEventEmitter(reactContext)
23
23
  );
24
24
  }
25
25
 
26
26
  @NonNull
27
27
  @Override
28
28
  public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
29
- // return Collections.emptyList();
30
- return Arrays.asList(
31
- new KeyboardInsetsViewManager()
32
- );
29
+ return Collections.emptyList();
33
30
  }
34
31
 
35
32
  }
package/lib/index.d.ts CHANGED
@@ -11,4 +11,3 @@ export * from './router';
11
11
  export * from './DeepLink';
12
12
  export * from './Route';
13
13
  export * from './Options';
14
- export * from './Keyboard';
package/lib/index.js CHANGED
@@ -13,4 +13,3 @@ export * from './router';
13
13
  export * from './DeepLink';
14
14
  export * from './Route';
15
15
  export * from './Options';
16
- export * from './Keyboard';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hybrid-navigation",
3
3
  "description": "React Native Navigation that supports seamless navigation between Native and React.",
4
- "version": "2.14.0-rc.4",
4
+ "version": "2.14.0",
5
5
  "main": "./lib/index.js",
6
6
  "typings": "./lib/index.d.ts",
7
7
  "react-native": "src/index",
@@ -66,6 +66,7 @@
66
66
  "react": "18.2.0",
67
67
  "react-native": "^0.71.0",
68
68
  "react-native-fast-image": "^8.5.11",
69
+ "react-native-keyboard-insets": "^1.0.0",
69
70
  "react-native-safe-area-context": "^4.5.0",
70
71
  "react-native-toast-hybrid": "^2.5.0",
71
72
  "react-redux": "^7.2.5",
package/src/index.ts CHANGED
@@ -16,4 +16,3 @@ export * from './router'
16
16
  export * from './DeepLink'
17
17
  export * from './Route'
18
18
  export * from './Options'
19
- export * from './Keyboard'
@@ -1,142 +0,0 @@
1
- package com.reactnative.hybridnavigation;
2
-
3
- import android.util.Log;
4
- import android.view.View;
5
- import android.view.ViewParent;
6
-
7
- import androidx.annotation.NonNull;
8
- import androidx.core.graphics.Insets;
9
- import androidx.core.view.OnApplyWindowInsetsListener;
10
- import androidx.core.view.WindowInsetsAnimationCompat;
11
- import androidx.core.view.WindowInsetsCompat;
12
-
13
- import com.facebook.common.logging.FLog;
14
- import com.facebook.react.bridge.Arguments;
15
- import com.facebook.react.bridge.WritableMap;
16
- import com.facebook.react.uimanager.PixelUtil;
17
- import com.facebook.react.uimanager.ThemedReactContext;
18
- import com.facebook.react.uimanager.UIManagerHelper;
19
- import com.facebook.react.uimanager.events.EventDispatcher;
20
- import com.facebook.react.uimanager.events.RCTEventEmitter;
21
- import com.navigation.androidx.EdgeInsets;
22
- import com.navigation.androidx.SystemUI;
23
-
24
- import java.util.List;
25
-
26
- public class KeyboardInsetsCallback extends WindowInsetsAnimationCompat.Callback implements OnApplyWindowInsetsListener {
27
-
28
- private final KeyboardInsetsView view;
29
- private final ThemedReactContext reactContext;
30
-
31
- public KeyboardInsetsCallback(KeyboardInsetsView view, ThemedReactContext reactContext) {
32
- super(WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_CONTINUE_ON_SUBTREE);
33
- this.view = view;
34
- this.reactContext = reactContext;
35
- }
36
-
37
- private View focusView;
38
- private boolean animating;
39
-
40
- @Override
41
- public void onPrepare(@NonNull WindowInsetsAnimationCompat animation) {
42
- animating = true;
43
- }
44
-
45
- @NonNull
46
- @Override
47
- public WindowInsetsAnimationCompat.BoundsCompat onStart(@NonNull WindowInsetsAnimationCompat animation, @NonNull WindowInsetsAnimationCompat.BoundsCompat bounds) {
48
- if (SystemUI.isImeVisible(view)) {
49
- focusView = view.findFocus();
50
- }
51
-
52
- if (!shouldHandleKeyboardTransition(focusView)) {
53
- return super.onStart(animation, bounds);
54
- }
55
-
56
- FLog.w("KeyboardInsets", "WindowInsetsAnimation.Callback onStart");
57
-
58
- if (SystemUI.isImeVisible(view)) {
59
- int keyboardHeight = SystemUI.imeHeight(view);
60
- WritableMap map = Arguments.createMap();
61
- map.putDouble("height", PixelUtil.toDIPFromPixel(keyboardHeight));
62
- reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(
63
- view.getId(),
64
- "topKeyboardHeightChanged",
65
- map);
66
- }
67
-
68
- return super.onStart(animation, bounds);
69
- }
70
-
71
- @Override
72
- public void onEnd(@NonNull WindowInsetsAnimationCompat animation) {
73
- super.onEnd(animation);
74
- animating = false;
75
-
76
- if (!shouldHandleKeyboardTransition(focusView)) {
77
- return;
78
- }
79
-
80
- FLog.w("KeyboardInsets", "WindowInsetsAnimation.Callback onEnd");
81
- if (!SystemUI.isImeVisible(view)) {
82
- focusView = null;
83
- }
84
- }
85
-
86
- @NonNull
87
- @Override
88
- public WindowInsetsCompat onProgress(@NonNull WindowInsetsCompat insets, @NonNull List<WindowInsetsAnimationCompat> runningAnimations) {
89
- if (!shouldHandleKeyboardTransition(focusView)) {
90
- return insets;
91
- }
92
-
93
- handleKeyboardTransition(insets);
94
-
95
- return WindowInsetsCompat.CONSUMED;
96
- }
97
-
98
- @Override
99
- public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
100
- if (shouldHandleKeyboardTransition(focusView) && !animating) {
101
- FLog.w("KeyboardInsets", "onApplyWindowInsets " + insets);
102
- handleKeyboardTransition(insets);
103
- }
104
- return insets;
105
- }
106
-
107
- private void handleKeyboardTransition(WindowInsetsCompat insets) {
108
- Insets imeInsets = insets.getInsets(WindowInsetsCompat.Type.ime());
109
- if (view.isAutoMode()) {
110
- EdgeInsets edgeInsets = SystemUI.getEdgeInsetsForView(focusView);
111
- float extraHeight = PixelUtil.toPixelFromDIP(view.getExtraHeight());
112
- Log.d("KeyboardInsets", "edgeInsets.bottom:" + edgeInsets.bottom + " imeInsets.bottom:" + imeInsets.bottom);
113
- view.setTranslationY(-Math.max(imeInsets.bottom - edgeInsets.bottom + extraHeight, 0));
114
-
115
- } else {
116
- EventDispatcher eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, view.getId());
117
- eventDispatcher.dispatchEvent(new KeyboardInsetsChangeEvent(view.getId(), imeInsets));
118
- }
119
- }
120
-
121
- private boolean shouldHandleKeyboardTransition(View focus) {
122
- if (focus != null) {
123
- KeyboardInsetsView insetsView = findClosestKeyboardInsetsView(focus);
124
- return insetsView == view;
125
- }
126
- return false;
127
- }
128
-
129
- private static KeyboardInsetsView findClosestKeyboardInsetsView(View focus) {
130
- ViewParent viewParent = focus.getParent();
131
- if (viewParent instanceof KeyboardInsetsView) {
132
- return (KeyboardInsetsView) viewParent;
133
- }
134
-
135
- if (viewParent instanceof View) {
136
- return findClosestKeyboardInsetsView((View) viewParent);
137
- }
138
-
139
- return null;
140
- }
141
-
142
- }
@@ -1,34 +0,0 @@
1
- package com.reactnative.hybridnavigation;
2
-
3
- import androidx.core.graphics.Insets;
4
-
5
- import com.facebook.react.bridge.Arguments;
6
- import com.facebook.react.bridge.WritableMap;
7
- import com.facebook.react.uimanager.PixelUtil;
8
- import com.facebook.react.uimanager.events.Event;
9
- import com.facebook.react.uimanager.events.RCTEventEmitter;
10
-
11
- public class KeyboardInsetsChangeEvent extends Event<KeyboardInsetsChangeEvent> {
12
-
13
- private final Insets insets;
14
-
15
- public KeyboardInsetsChangeEvent(int viewId, Insets insets) {
16
- super(viewId);
17
- this.insets = insets;
18
- }
19
-
20
- @Override
21
- public String getEventName() {
22
- return "topInsetsChanged";
23
- }
24
-
25
- @Override
26
- public void dispatch(RCTEventEmitter rctEventEmitter) {
27
- WritableMap map = Arguments.createMap();
28
- map.putDouble("top", PixelUtil.toDIPFromPixel(insets.top));
29
- map.putDouble("left", PixelUtil.toDIPFromPixel(insets.left));
30
- map.putDouble("right", PixelUtil.toDIPFromPixel(insets.right));
31
- map.putDouble("bottom", PixelUtil.toDIPFromPixel(insets.bottom));
32
- rctEventEmitter.receiveEvent(getViewTag(), getEventName(), map);
33
- }
34
- }
@@ -1,52 +0,0 @@
1
- package com.reactnative.hybridnavigation;
2
-
3
- import android.view.View;
4
-
5
- import androidx.annotation.NonNull;
6
-
7
- import com.facebook.react.bridge.Arguments;
8
- import com.facebook.react.bridge.Callback;
9
- import com.facebook.react.bridge.ReactApplicationContext;
10
- import com.facebook.react.bridge.ReactContextBaseJavaModule;
11
- import com.facebook.react.bridge.ReactMethod;
12
- import com.facebook.react.bridge.UiThreadUtil;
13
- import com.facebook.react.bridge.WritableMap;
14
- import com.facebook.react.uimanager.PixelUtil;
15
- import com.facebook.react.uimanager.UIManagerModule;
16
- import com.navigation.androidx.EdgeInsets;
17
- import com.navigation.androidx.SystemUI;
18
-
19
- public class KeyboardInsetsModule extends ReactContextBaseJavaModule {
20
-
21
- public KeyboardInsetsModule(ReactApplicationContext reactContext) {
22
- super(reactContext);
23
- }
24
-
25
- @NonNull
26
- @Override
27
- public String getName() {
28
- return "KeyboardInsetsModule";
29
- }
30
-
31
- @ReactMethod
32
- public void getEdgeInsetsForView(int viewTag, Callback callback) {
33
- UiThreadUtil.runOnUiThread(() -> {
34
- UIManagerModule uiManagerModule = getReactApplicationContext().getNativeModule(UIManagerModule.class);
35
- View view = uiManagerModule.resolveView(viewTag);
36
- WritableMap map = Arguments.createMap();
37
- map.putDouble("top", 0);
38
- map.putDouble("left", 0);
39
- map.putDouble("right", 0);
40
- map.putDouble("bottom", 0);
41
- if (view != null) {
42
- EdgeInsets insets = SystemUI.getEdgeInsetsForView(view);
43
- map.putDouble("top", PixelUtil.toDIPFromPixel(insets.top));
44
- map.putDouble("left", PixelUtil.toDIPFromPixel(insets.left));
45
- map.putDouble("right", PixelUtil.toDIPFromPixel(insets.right));
46
- map.putDouble("bottom", PixelUtil.toDIPFromPixel(insets.bottom));
47
- }
48
- callback.invoke(map);
49
- });
50
- }
51
-
52
- }
@@ -1,33 +0,0 @@
1
- package com.reactnative.hybridnavigation;
2
-
3
- import android.content.Context;
4
-
5
- import com.facebook.react.views.view.ReactViewGroup;
6
-
7
- public class KeyboardInsetsView extends ReactViewGroup {
8
-
9
- private String mode = "auto";
10
-
11
- private float extraHeight = 0.0f;
12
-
13
- public KeyboardInsetsView(Context context) {
14
- super(context);
15
- }
16
-
17
- public void setMode(String mode) {
18
- this.mode = mode;
19
- }
20
-
21
- public boolean isAutoMode() {
22
- return this.mode.equals("auto");
23
- }
24
-
25
- public void setExtraHeight(float extraHeight) {
26
- this.extraHeight = extraHeight;
27
- }
28
-
29
- public float getExtraHeight() {
30
- return this.extraHeight;
31
- }
32
-
33
- }
@@ -1,53 +0,0 @@
1
- package com.reactnative.hybridnavigation;
2
-
3
- import androidx.annotation.NonNull;
4
- import androidx.annotation.Nullable;
5
- import androidx.core.view.ViewCompat;
6
-
7
- import com.facebook.react.common.MapBuilder;
8
- import com.facebook.react.uimanager.ThemedReactContext;
9
- import com.facebook.react.uimanager.ViewGroupManager;
10
- import com.facebook.react.uimanager.annotations.ReactProp;
11
-
12
- import java.util.Map;
13
-
14
- public class KeyboardInsetsViewManager extends ViewGroupManager<KeyboardInsetsView> {
15
-
16
- public static final String REACT_CLASS = "KeyboardInsetsView";
17
-
18
- @NonNull
19
- @Override
20
- public String getName() {
21
- return REACT_CLASS;
22
- }
23
-
24
- @NonNull
25
- @Override
26
- protected KeyboardInsetsView createViewInstance(@NonNull ThemedReactContext themedReactContext) {
27
- KeyboardInsetsView view = new KeyboardInsetsView(themedReactContext);
28
- KeyboardInsetsCallback callback = new KeyboardInsetsCallback(view, themedReactContext);
29
- ViewCompat.setWindowInsetsAnimationCallback(view, callback);
30
- ViewCompat.setOnApplyWindowInsetsListener(view, callback);
31
- return view;
32
- }
33
-
34
- @ReactProp(name = "mode")
35
- public void setMode(KeyboardInsetsView view, String mode) {
36
- view.setMode(mode);
37
- }
38
-
39
- @ReactProp(name = "extraHeight")
40
- public void setExtraHeight(KeyboardInsetsView view, float extraHeight) {
41
- view.setExtraHeight(extraHeight);
42
- }
43
-
44
- @Nullable
45
- @Override
46
- public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
47
- return MapBuilder.of(
48
- "topInsetsChanged", MapBuilder.of("registrationName", "onInsetsChanged"),
49
- "topKeyboardHeightChanged", MapBuilder.of("registrationName", "onKeyboardHeightChanged")
50
- );
51
- }
52
-
53
- }
@@ -1,9 +0,0 @@
1
- #import <React/RCTBridgeModule.h>
2
-
3
- NS_ASSUME_NONNULL_BEGIN
4
-
5
- @interface HBDKeyboardInsetsModule : NSObject <RCTBridgeModule>
6
-
7
- @end
8
-
9
- NS_ASSUME_NONNULL_END
@@ -1,34 +0,0 @@
1
- #import "HBDKeyboardInsetsModule.h"
2
- #import <React/RCTLog.h>
3
- #import <React/RCTUIManager.h>
4
-
5
- @implementation HBDKeyboardInsetsModule
6
-
7
- RCT_EXPORT_MODULE(KeyboardInsetsModule)
8
-
9
- @synthesize bridge;
10
-
11
- + (BOOL)requiresMainQueueSetup {
12
- return YES;
13
- }
14
-
15
- - (dispatch_queue_t)methodQueue {
16
- return dispatch_get_main_queue();
17
- }
18
-
19
- RCT_EXPORT_METHOD(getEdgeInsetsForView:(nonnull NSNumber *)reactTag callback:(RCTResponseSenderBlock)callback) {
20
- RCTUIManager* uiManager = [self.bridge moduleForClass:[RCTUIManager class]];
21
- UIView* view = [uiManager viewForReactTag:reactTag];
22
- CGRect windowFrame = [view.window convertRect:view.frame fromView:view.superview];
23
-
24
- callback(@[
25
- @{
26
- @"left": @(MAX(0, windowFrame.origin.x)),
27
- @"top": @(MAX(0, windowFrame.origin.y)),
28
- @"right": @(MAX(0, CGRectGetMaxX(view.window.bounds) - CGRectGetMaxX(windowFrame))),
29
- @"bottom": @(MAX(0, CGRectGetMaxY(view.window.bounds) - CGRectGetMaxY(windowFrame))),
30
- }
31
- ]);
32
- }
33
-
34
- @end
@@ -1,17 +0,0 @@
1
- #import <React/RCTView.h>
2
-
3
- NS_ASSUME_NONNULL_BEGIN
4
-
5
- @interface HBDKeyboardInsetsView : RCTView
6
-
7
-
8
- @property(nonatomic, copy) RCTDirectEventBlock onInsetsChanged;
9
- @property(nonatomic, copy) RCTDirectEventBlock onKeyboardHeightChanged;
10
-
11
- @property(nonatomic, copy) NSString *mode;
12
- @property(nonatomic, assign) CGFloat extraHeight;
13
-
14
-
15
- @end
16
-
17
- NS_ASSUME_NONNULL_END
@@ -1,203 +0,0 @@
1
- #import "HBDKeyboardInsetsView.h"
2
- #import <React/RCTLog.h>
3
- #import <React/RCTUIManager.h>
4
-
5
- @implementation HBDKeyboardInsetsView {
6
- UIView *_focusView;
7
- CGFloat _edgeBottom;
8
-
9
- CADisplayLink *_displayLink;
10
- UIView *_keyboardView;
11
- CGFloat _keyboardHeight;
12
- }
13
-
14
- - (instancetype)init {
15
- if (self = [super init]) {
16
- _mode = @"auto";
17
- }
18
- return self;
19
- }
20
-
21
- - (void)willMoveToWindow:(UIWindow *)newWindow {
22
- if (!newWindow) {
23
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
24
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidShowNotification object:nil];
25
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
26
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidHideNotification object:nil];
27
- }
28
- }
29
-
30
- - (void)didMoveToWindow {
31
- if (self.window) {
32
- [[NSNotificationCenter defaultCenter] addObserver:self
33
- selector:@selector(keyboardWillShow:)
34
- name:UIKeyboardWillShowNotification
35
- object:nil];
36
-
37
- [[NSNotificationCenter defaultCenter] addObserver:self
38
- selector:@selector(keyboardDidShow:)
39
- name:UIKeyboardDidShowNotification
40
- object:nil];
41
-
42
- [[NSNotificationCenter defaultCenter] addObserver:self
43
- selector:@selector(keyboardWillHide:)
44
- name:UIKeyboardWillHideNotification
45
- object:nil];
46
-
47
- [[NSNotificationCenter defaultCenter] addObserver:self
48
- selector:@selector(keyboardDidHide:)
49
- name:UIKeyboardDidHideNotification
50
- object:nil];
51
- }
52
- }
53
-
54
- - (void)keyboardWillShow:(NSNotification *)notification {
55
- UIView *focusView = [HBDKeyboardInsetsView findFocusView:self];
56
- _focusView = focusView;
57
- if (![self shouldHandleKeyboardTransition:focusView]) {
58
- return;
59
- }
60
-
61
- _keyboardView = [HBDKeyboardInsetsView findKeyboardView];
62
-
63
- NSDictionary *userInfo = [notification userInfo];
64
- CGRect keyboardRect = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
65
- CGFloat keyboardHeight = keyboardRect.size.height;
66
- _keyboardHeight = keyboardHeight;
67
- self.onKeyboardHeightChanged(@{
68
- @"height": @(keyboardHeight)
69
- });
70
-
71
- if ([self.mode isEqualToString:@"auto"] && CGAffineTransformEqualToTransform(self.transform, CGAffineTransformIdentity)) {
72
- CGRect windowFrame = [self.window convertRect:focusView.frame fromView:focusView.superview];
73
- _edgeBottom = MAX(CGRectGetMaxY(self.window.bounds) - CGRectGetMaxY(windowFrame), 0);
74
- }
75
-
76
- RCTLogInfo(@"[Navigation] keyboardWillShow startWatchKeyboardTransition");
77
- [self startWatchKeyboardTransition];
78
- }
79
-
80
- - (void)keyboardDidShow:(NSNotification *)notification {
81
- if ([self shouldHandleKeyboardTransition:_focusView]) {
82
- RCTLogInfo(@"[Navigation] keyboardDidShow stopWatchKeyboardTransition");
83
- [self stopWatchKeyboardTransition];
84
- [self handleKeyboardTransition:_keyboardHeight];
85
- }
86
- }
87
-
88
- - (void)keyboardWillHide:(NSNotification *)notification {
89
- if ([self shouldHandleKeyboardTransition:_focusView]) {
90
- RCTLogInfo(@"[Navigation] keyboardWillHide startWatchKeyboardTransition");
91
- _keyboardView = [HBDKeyboardInsetsView findKeyboardView];
92
- [self startWatchKeyboardTransition];
93
- }
94
- }
95
-
96
-
97
- - (void)keyboardDidHide:(NSNotification *)notification {
98
- if ([self shouldHandleKeyboardTransition:_focusView]) {
99
- RCTLogInfo(@"[Navigation] keyboardDidHide stopWatchKeyboardTransition");
100
- [self stopWatchKeyboardTransition];
101
- [self handleKeyboardTransition:0];
102
- }
103
- _focusView = nil;
104
- _edgeBottom = 0;
105
- }
106
-
107
- - (BOOL)shouldHandleKeyboardTransition:(UIView *)focusView {
108
- if (focusView) {
109
- HBDKeyboardInsetsView *closet = [HBDKeyboardInsetsView findClosetKeyboardInsetsView:focusView];
110
- return closet == self;
111
- }
112
- return NO;
113
- }
114
-
115
-
116
- - (void)startWatchKeyboardTransition {
117
- [self stopWatchKeyboardTransition];
118
- _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(watchKeyboardTransition)];
119
- _displayLink.preferredFramesPerSecond = 120;
120
- [_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
121
-
122
- }
123
-
124
- - (void)stopWatchKeyboardTransition {
125
- [_displayLink invalidate];
126
- _displayLink = nil;
127
- }
128
-
129
- - (void)watchKeyboardTransition {
130
- if (_keyboardView == nil) {
131
- return;
132
- }
133
-
134
- CGFloat keyboardFrameY = [_keyboardView.layer presentationLayer].frame.origin.y;
135
- CGFloat keyboardWindowH = _keyboardView.window.bounds.size.height;
136
- [self handleKeyboardTransition:(keyboardWindowH - keyboardFrameY)];
137
- }
138
-
139
- - (void)handleKeyboardTransition:(CGFloat)position {
140
- if ([self.mode isEqualToString:@"auto"]) {
141
- if (_focusView) {
142
- CGFloat translationY = -MAX(position - _edgeBottom + self.extraHeight, 0);
143
- self.transform = CGAffineTransformMakeTranslation(0, translationY);
144
- }
145
- } else {
146
- self.onInsetsChanged(@{
147
- @"top": @0,
148
- @"left": @0,
149
- @"right": @0,
150
- @"bottom": @(position)
151
- });
152
- }
153
-
154
- }
155
-
156
- + (UIView *)findKeyboardView {
157
- NSArray<UIWindow *> *windows = UIApplication.sharedApplication.windows;
158
- for (UIWindow *window in windows) {
159
- if ([window.description hasPrefix:@"<UITextEffectsWindow"]) {
160
- for (UIView *subview in window.subviews) {
161
- if ([subview.description hasPrefix:@"<UIInputSetContainerView"]) {
162
- for (UIView *hostView in subview.subviews) {
163
- if ([hostView.description hasPrefix:@"<UIInputSetHostView"]) {
164
- return hostView;
165
- }
166
- }
167
- break;
168
- }
169
- }
170
- break;
171
- }
172
- }
173
- return nil;
174
- }
175
-
176
- + (UIView *)findFocusView:(UIView *)view {
177
- if ([view isFirstResponder]) {
178
- return view;
179
- }
180
-
181
- for (UIView *child in view.subviews) {
182
- UIView *focus = [self findFocusView:child];
183
- if (focus) {
184
- return focus;
185
- }
186
- }
187
-
188
- return nil;
189
- }
190
-
191
- + (HBDKeyboardInsetsView *)findClosetKeyboardInsetsView:(UIView *)view {
192
- if ([view isKindOfClass:[HBDKeyboardInsetsView class]]) {
193
- return (HBDKeyboardInsetsView *)view;
194
- }
195
-
196
- if (view.superview) {
197
- return [self findClosetKeyboardInsetsView:view.superview];
198
- }
199
-
200
- return nil;
201
- }
202
-
203
- @end
@@ -1,9 +0,0 @@
1
- #import <React/RCTUIManager.h>
2
-
3
- NS_ASSUME_NONNULL_BEGIN
4
-
5
- @interface HBDKeyboardInsetsViewManager : RCTViewManager
6
-
7
- @end
8
-
9
- NS_ASSUME_NONNULL_END
@@ -1,18 +0,0 @@
1
- #import "HBDKeyboardInsetsViewManager.h"
2
- #import "HBDKeyboardInsetsView.h"
3
-
4
- @implementation HBDKeyboardInsetsViewManager
5
-
6
- RCT_EXPORT_MODULE(KeyboardInsetsView)
7
-
8
- - (UIView *)view {
9
- return [[HBDKeyboardInsetsView alloc] init];
10
- }
11
-
12
- RCT_EXPORT_VIEW_PROPERTY(mode, NSString)
13
- RCT_EXPORT_VIEW_PROPERTY(extraHeight, CGFloat)
14
-
15
- RCT_EXPORT_VIEW_PROPERTY(onInsetsChanged, RCTDirectEventBlock)
16
- RCT_EXPORT_VIEW_PROPERTY(onKeyboardHeightChanged, RCTDirectEventBlock)
17
-
18
- @end
package/lib/Keyboard.d.ts DELETED
@@ -1,17 +0,0 @@
1
- /// <reference types="react" />
2
- import { Animated, Insets, ViewProps } from 'react-native';
3
- interface AnimatedInsets {
4
- top: Animated.Value;
5
- left: Animated.Value;
6
- right: Animated.Value;
7
- bottom: Animated.Value;
8
- }
9
- interface KeyboardInsetsViewProps extends ViewProps {
10
- mode?: 'auto' | 'manual';
11
- extraHeight?: number;
12
- }
13
- export declare function KeyboardInsetsView(props: KeyboardInsetsViewProps): JSX.Element;
14
- export declare function useKeyboardInsets(): AnimatedInsets;
15
- export declare function useKeyboardHeight(): number;
16
- export declare function getEdgeInsetsForView(viewTag: number, callback: (insets: Insets) => void): void;
17
- export {};
package/lib/Keyboard.js DELETED
@@ -1,57 +0,0 @@
1
- import React, { createContext, useCallback, useContext, useMemo, useState } from 'react';
2
- import { Animated, NativeModules, requireNativeComponent, } from 'react-native';
3
- const NativeKeyboardInsetsView = requireNativeComponent('KeyboardInsetsView');
4
- const NativeKeyboardInsetsViewAnimated = Animated.createAnimatedComponent(NativeKeyboardInsetsView);
5
- const defaultContext = {
6
- insets: {
7
- top: new Animated.Value(0),
8
- left: new Animated.Value(0),
9
- right: new Animated.Value(0),
10
- bottom: new Animated.Value(0),
11
- },
12
- keyboardHeight: 0,
13
- };
14
- const KeyboardInsetsContext = createContext(defaultContext);
15
- export function KeyboardInsetsView(props) {
16
- const { children, ...rest } = props;
17
- const insets = useMemo(() => ({
18
- top: new Animated.Value(0),
19
- left: new Animated.Value(0),
20
- right: new Animated.Value(0),
21
- bottom: new Animated.Value(0),
22
- }), []);
23
- const [keyboardHeight, setKeyboardHeight] = useState(0);
24
- const onInsetsChanged = useMemo(() => Animated.event([
25
- {
26
- nativeEvent: {
27
- top: insets.top,
28
- left: insets.left,
29
- right: insets.right,
30
- bottom: insets.bottom,
31
- },
32
- },
33
- ], {
34
- useNativeDriver: true,
35
- listener: event => {
36
- console.log(event.nativeEvent);
37
- },
38
- }), [insets]);
39
- const onKeyboardHeightChanged = useCallback((event) => {
40
- setKeyboardHeight(event.nativeEvent.height);
41
- }, []);
42
- return (<KeyboardInsetsContext.Provider value={{ insets, keyboardHeight }}>
43
- <NativeKeyboardInsetsViewAnimated onInsetsChanged={onInsetsChanged} onKeyboardHeightChanged={onKeyboardHeightChanged} style={{ flex: 1 }} {...rest}>
44
- {children}
45
- </NativeKeyboardInsetsViewAnimated>
46
- </KeyboardInsetsContext.Provider>);
47
- }
48
- export function useKeyboardInsets() {
49
- return useContext(KeyboardInsetsContext).insets;
50
- }
51
- export function useKeyboardHeight() {
52
- return useContext(KeyboardInsetsContext).keyboardHeight;
53
- }
54
- const KeyboardInsetsModule = NativeModules.KeyboardInsetsModule;
55
- export function getEdgeInsetsForView(viewTag, callback) {
56
- KeyboardInsetsModule.getEdgeInsetsForView(viewTag, callback);
57
- }
package/src/Keyboard.tsx DELETED
@@ -1,128 +0,0 @@
1
- import React, { createContext, useCallback, useContext, useMemo, useState } from 'react'
2
- import {
3
- Animated,
4
- Insets,
5
- NativeModule,
6
- NativeModules,
7
- NativeSyntheticEvent,
8
- requireNativeComponent,
9
- ViewProps,
10
- } from 'react-native'
11
-
12
- interface KeyboardHeight {
13
- height: number
14
- }
15
-
16
- interface NativeKeyboardInsetsViewProps {
17
- mode?: 'auto' | 'manual'
18
- extraHeight?: number
19
- onInsetsChanged?: (event: NativeSyntheticEvent<Insets>) => void
20
- onKeyboardHeightChanged?: (event: NativeSyntheticEvent<KeyboardHeight>) => void
21
- }
22
-
23
- const NativeKeyboardInsetsView = requireNativeComponent<NativeKeyboardInsetsViewProps & ViewProps>(
24
- 'KeyboardInsetsView',
25
- )
26
-
27
- const NativeKeyboardInsetsViewAnimated = Animated.createAnimatedComponent(NativeKeyboardInsetsView)
28
-
29
- interface AnimatedInsets {
30
- top: Animated.Value
31
- left: Animated.Value
32
- right: Animated.Value
33
- bottom: Animated.Value
34
- }
35
-
36
- type KeyboardInsetsContext = {
37
- insets: AnimatedInsets
38
- keyboardHeight: number
39
- }
40
-
41
- const defaultContext: KeyboardInsetsContext = {
42
- insets: {
43
- top: new Animated.Value(0),
44
- left: new Animated.Value(0),
45
- right: new Animated.Value(0),
46
- bottom: new Animated.Value(0),
47
- },
48
- keyboardHeight: 0,
49
- }
50
-
51
- const KeyboardInsetsContext = createContext<KeyboardInsetsContext>(defaultContext)
52
-
53
- interface KeyboardInsetsViewProps extends ViewProps {
54
- mode?: 'auto' | 'manual'
55
- extraHeight?: number
56
- }
57
-
58
- export function KeyboardInsetsView(props: KeyboardInsetsViewProps) {
59
- const { children, ...rest } = props
60
- const insets = useMemo(
61
- () => ({
62
- top: new Animated.Value(0),
63
- left: new Animated.Value(0),
64
- right: new Animated.Value(0),
65
- bottom: new Animated.Value(0),
66
- }),
67
- [],
68
- )
69
-
70
- const [keyboardHeight, setKeyboardHeight] = useState(0)
71
-
72
- const onInsetsChanged = useMemo(
73
- () =>
74
- Animated.event<Insets>(
75
- [
76
- {
77
- nativeEvent: {
78
- top: insets.top,
79
- left: insets.left,
80
- right: insets.right,
81
- bottom: insets.bottom,
82
- },
83
- },
84
- ],
85
- {
86
- useNativeDriver: true,
87
- listener: event => {
88
- console.log(event.nativeEvent)
89
- },
90
- },
91
- ),
92
- [insets],
93
- )
94
-
95
- const onKeyboardHeightChanged = useCallback((event: NativeSyntheticEvent<KeyboardHeight>) => {
96
- setKeyboardHeight(event.nativeEvent.height)
97
- }, [])
98
-
99
- return (
100
- <KeyboardInsetsContext.Provider value={{ insets, keyboardHeight }}>
101
- <NativeKeyboardInsetsViewAnimated
102
- onInsetsChanged={onInsetsChanged}
103
- onKeyboardHeightChanged={onKeyboardHeightChanged}
104
- style={{ flex: 1 }}
105
- {...rest}>
106
- {children}
107
- </NativeKeyboardInsetsViewAnimated>
108
- </KeyboardInsetsContext.Provider>
109
- )
110
- }
111
-
112
- export function useKeyboardInsets() {
113
- return useContext(KeyboardInsetsContext).insets
114
- }
115
-
116
- export function useKeyboardHeight() {
117
- return useContext(KeyboardInsetsContext).keyboardHeight
118
- }
119
-
120
- interface KeyboardInsetsModuleInterface extends NativeModule {
121
- getEdgeInsetsForView(viewTag: number, callback: (insets: Insets) => void): void
122
- }
123
-
124
- const KeyboardInsetsModule: KeyboardInsetsModuleInterface = NativeModules.KeyboardInsetsModule
125
-
126
- export function getEdgeInsetsForView(viewTag: number, callback: (insets: Insets) => void) {
127
- KeyboardInsetsModule.getEdgeInsetsForView(viewTag, callback)
128
- }