Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compute correct Keyboard Height with Notch #30919

Closed
wants to merge 11 commits into from
Prev Previous commit
Next Next commit
add method simulateCheckForKeyboardForTesting
The method has annotation @VisibleForTesting and is available only for
testing purposes
  • Loading branch information
fabOnReact authored and cortinico committed Sep 28, 2021
commit 0828998f9a952f2186641c3b8d6fc65f37618745
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,11 @@ public void runApplication() {
mJSTouchDispatcher = new JSTouchDispatcher(this);
}

@VisibleForTesting
/* package */ void simulateCheckForKeyboardForTesting() {
getCustomGlobalLayoutListener().checkForKeyboardEvents();
}

private CustomGlobalLayoutListener getCustomGlobalLayoutListener() {
if (mCustomGlobalLayoutListener == null) {
mCustomGlobalLayoutListener = new CustomGlobalLayoutListener();
Expand Down
35 changes: 16 additions & 19 deletions ReactAndroid/src/test/java/com/facebook/react/RootViewTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,16 @@

package com.facebook.react;

import com.facebook.react.uimanager.ReactRoot;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.bridge.WritableMap;
import android.util.Log;
import android.graphics.Rect;

import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import org.mockito.Mockito;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import android.graphics.Rect;
import android.view.MotionEvent;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.CatalystInstance;
Expand All @@ -35,6 +27,7 @@
import com.facebook.react.bridge.ReactTestHelper;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.common.SystemClock;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.uimanager.DisplayMetricsHolder;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.events.Event;
Expand All @@ -46,6 +39,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito;
Expand Down Expand Up @@ -225,24 +219,27 @@ public void testCheckForKeyboardEvents() {
when(instanceManager.getCurrentReactContext()).thenReturn(mReactContext);
UIManagerModule uiManager = mock(UIManagerModule.class);
EventDispatcher eventDispatcher = mock(EventDispatcher.class);
fabOnReact marked this conversation as resolved.
Show resolved Hide resolved
DeviceEventManagerModule.RCTDeviceEventEmitter eventEmitterModuleMock = mock(DeviceEventManagerModule.RCTDeviceEventEmitter.class);
when(mReactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)).thenReturn(eventEmitterModuleMock);
DeviceEventManagerModule.RCTDeviceEventEmitter eventEmitterModuleMock =
mock(DeviceEventManagerModule.RCTDeviceEventEmitter.class);
when(mReactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class))
.thenReturn(eventEmitterModuleMock);
when(mCatalystInstanceMock.getNativeModule(UIManagerModule.class)).thenReturn(uiManager);
when(uiManager.getEventDispatcher()).thenReturn(eventDispatcher);

int rootViewId = 7;

ReactRootView rootView = new ReactRootView(mReactContext) {
@Override
public void getWindowVisibleDisplayFrame(Rect outRect) {
outRect.bottom += 100;
}
};
ReactRootView rootView =
new ReactRootView(mReactContext) {
@Override
public void getWindowVisibleDisplayFrame(Rect outRect) {
outRect.bottom += 100;
}
};
rootView.setId(rootViewId);
rootView.setRootViewTag(rootViewId);
rootView.startReactApplication(instanceManager, "");
rootView.simulateAttachForTesting();
rootView.getCustomGlobalLayoutListener().checkForKeyboardEvents();
verify(instanceManager, Mockito.times(2)).getCurrentReactContext();
rootView.simulateCheckForKeyboardForTesting();
verify(instanceManager, Mockito.times(1)).getCurrentReactContext();
}
}