Skip to content

Commit

Permalink
Merge pull request #2 from ykhateeb/0.1.3
Browse files Browse the repository at this point in the history
v0.1.3
  • Loading branch information
ykhateeb committed Dec 16, 2023
2 parents e133a70 + d3c3c8a commit 23d43b7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ cd ios && pod install

```js
import React from 'react';
import { SafeAreaView, TextInput, StyleSheet } from 'react-native';
import { KeyboardMovingView } from 'react-native-keyboard-moving-view';
import { TextInput, StyleSheet, SafeAreaView } from 'react-native';

export default function App() {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class RootViewDeferringInsetsHandler extends WindowInsetsAnimationCompat.
private float mBottomHeight = 0;
private int mLastIMEHeight = 0;
private boolean mIsIMEDidShow = false;
private boolean mShouldHandlePositionTransition = false;

public RootViewDeferringInsetsHandler(ThemedReactContext context, KeyboardMovingViewView view) {
super(WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_STOP);
Expand Down Expand Up @@ -106,7 +107,7 @@ public WindowInsetsCompat onProgress(@NonNull WindowInsetsCompat insets, @NonNul
mView.updateProps(JavaOnlyMap.of("paddingBottom", PixelUtil.toDIPFromPixel((currentIMEHeight + (extraHeight * interpolatedFraction)) - (mBottomHeight * interpolatedFraction))));
}

if (behavior.equals("position")) {
if (behavior.equals("position") && mShouldHandlePositionTransition) {
float translationY = (currentIMEHeight - (mFocusViewBottomHeight * interpolatedFraction)) + (extraHeight * interpolatedFraction);
mView.setTranslationY(-Math.max(translationY, 0));
}
Expand All @@ -118,7 +119,6 @@ public WindowInsetsCompat onProgress(@NonNull WindowInsetsCompat insets, @NonNul
@Override
public WindowInsetsAnimationCompat.BoundsCompat onStart(@NonNull WindowInsetsAnimationCompat animation, @NonNull WindowInsetsAnimationCompat.BoundsCompat bounds) {
String behavior = mView.getBehavior();

boolean isIMEVisible = SystemUIUtils.isIMEVisible(mView);

if(isIMEVisible){
Expand All @@ -138,6 +138,7 @@ public WindowInsetsAnimationCompat.BoundsCompat onStart(@NonNull WindowInsetsAni
if (isIMEVisible && shouldHandleTransition()) {
adjustScrollViewOffsetIfNeeded(SystemUIUtils.findFocusView(mView), false);
mFocusViewBottomHeight = SystemUIUtils.getScreenHeight(mContext) - SystemUIUtils.getFocusViewYPosition(mView);
mShouldHandlePositionTransition = true;
}
}

Expand All @@ -148,14 +149,16 @@ public WindowInsetsAnimationCompat.BoundsCompat onStart(@NonNull WindowInsetsAni
public void onEnd(@NonNull WindowInsetsAnimationCompat animation) {
super.onEnd(animation);
boolean isIMEVisible = SystemUIUtils.isIMEVisible(mView);
//IME did show
if(isIMEVisible){
mIsIMEDidShow = true ;
mView.onKeyboardDidShowEvent();
}else{
//IME did hide
mIsIMEDidShow = false ;
mShouldHandlePositionTransition = false;
mView.onKeyboardDidHideEvent();
}

}

private boolean shouldHandleTransition() {
Expand Down
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ PODS:
- React-jsinspector (0.72.7)
- React-logger (0.72.7):
- glog
- react-native-keyboard-moving-view (0.1.1):
- react-native-keyboard-moving-view (0.1.3):
- RCT-Folly (= 2021.07.22.00)
- React-Core
- React-NativeModulesApple (0.72.7):
Expand Down Expand Up @@ -693,7 +693,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: c49502e5d02112247ee4526bc3ccfc891ae3eb9b
React-jsinspector: 8baadae51f01d867c3921213a25ab78ab4fbcd91
React-logger: 8edc785c47c8686c7962199a307015e2ce9a0e4f
react-native-keyboard-moving-view: 4267f39083885e9d09070cb28796edf5086ade53
react-native-keyboard-moving-view: 1e003026e3431d0f656d102287f2389098f7523c
React-NativeModulesApple: b6868ee904013a7923128892ee4a032498a1024a
React-perflogger: 31ea61077185eb1428baf60c0db6e2886f141a5a
React-RCTActionSheet: 392090a3abc8992eb269ef0eaa561750588fc39d
Expand Down
28 changes: 13 additions & 15 deletions ios/KeyboardMovingView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ - (void)updatePadding:(CGFloat)keyboardHeight {
CGFloat screenHeight = [SystemUIUtils screenHeight];
CGFloat borderBottomWidth = MAX(MAX(self.borderWidth, self.borderBottomWidth)/** return -1 if there is no border set */, 0);
CGFloat containerBottomHeight = screenHeight - (containerYPosition - borderBottomWidth);

NSDictionary *props = @{
@"paddingBottom":@(keyboardHeight == 0 ? keyboardHeight : MAX((keyboardHeight - containerBottomHeight), 0) + extraHeight)
};
Expand All @@ -105,11 +105,11 @@ - (void)transalteYPosition:(TranslationDirection)direction keyboardHeight:(NSInt
self.transform = CGAffineTransformMakeTranslation(0, (direction == TranslationDirectionTop ? -translationValue : 0));
}

- (bool)shouldHandleTransition:(CGFloat)keyboardHeight{
- (bool)shouldHandleTransition{
CGFloat screenHeight = [SystemUIUtils screenHeight];
CGFloat focusViewYPosition = [SystemUIUtils focusViewYPosition:self];
CGFloat bottomHeight = screenHeight - focusViewYPosition;/** height between View and bottom of screen */
return bottomHeight < keyboardHeight;
return bottomHeight < _keyboardHeight;
}

- (void)keyboardWillShow:(NSNotification *)notification {
Expand All @@ -131,23 +131,21 @@ - (void)keyboardWillShow:(NSNotification *)notification {
}

if([self.behavior isEqualToString:@"position"]){
if(![self shouldHandleTransition:keyboardHeight]){
return;
if([self shouldHandleTransition]){
[self adjustScrollViewOffsetIfNeeded:[SystemUIUtils findFocusView:self] isAnimationEnabled:NO];

CGFloat screenHeight = [SystemUIUtils screenHeight];
CGFloat focusViewYPosition = [SystemUIUtils focusViewYPosition:self];
_focusViewBottomHeight = MAX(screenHeight - focusViewYPosition, 0);

[self transalteYPosition:TranslationDirectionTop keyboardHeight:keyboardHeight duration:duration curve:curve iskeyboardFrameChanged:NO];
}

[self adjustScrollViewOffsetIfNeeded:[SystemUIUtils findFocusView:self] isAnimationEnabled:NO];

CGFloat screenHeight = [SystemUIUtils screenHeight];
CGFloat focusViewYPosition = [SystemUIUtils focusViewYPosition:self];
_focusViewBottomHeight = MAX(screenHeight - focusViewYPosition, 0);

[self transalteYPosition:TranslationDirectionTop keyboardHeight:keyboardHeight duration:duration curve:curve iskeyboardFrameChanged:NO];
}

if(self.onKeyboardWillShow){
self.onKeyboardWillShow(nil);
}

_isKeyboardWillShow = YES;
}

Expand All @@ -169,7 +167,7 @@ - (void)keyboardWillHide:(NSNotification *)notification {
if(self.onKeyboardWillHide){
self.onKeyboardWillHide(nil);
}

_isKeyboardWillShow = NO;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-keyboard-moving-view",
"version": "0.1.2",
"version": "0.1.3",
"description": "Out-of-the-box alternative to KeyboardAvoidingView, that provides identical behavior on both iOS and Android, with more extra features",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down

0 comments on commit 23d43b7

Please sign in to comment.