Skip to content

Commit 9930d6e

Browse files
committed
Merge branch 'feat/rn77-android-newarch' into daniel/rn77-ios-new-arch
# Conflicts: # package-lock.json # scripts/start.js
2 parents 56152f3 + e11fd53 commit 9930d6e

33 files changed

Lines changed: 3423 additions & 4907 deletions

File tree

e2e/Utils.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,15 @@ const utils = {
6464

6565
},
6666
expectImagesToBeNotEqual: (imagePath, expectedImagePath) => {
67-
let isDifferent = false;
6867
try {
6968
bitmapDiff(imagePath, expectedImagePath);
7069
} catch (error) {
71-
isDifferent = true;
70+
return
7271
}
7372

74-
if (!isDifferent) {
75-
throw new Error(
76-
`Expected bitmaps at '${imagePath}' and '${expectedImagePath}' to be different`,
77-
);
78-
}
73+
throw new Error(
74+
`Expected bitmaps at '${imagePath}' and '${expectedImagePath}' to be different`,
75+
);
7976
},
8077
};
8178

lib/android/app/src/main/java/com/reactnativenavigation/FeatureToggles.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package com.reactnativenavigation
33
import androidx.annotation.VisibleForTesting
44

55
enum class RNNToggles {
6-
TOP_BAR_COLOR_ANIMATION,
6+
TOP_BAR_COLOR_ANIMATION__PUSH,
7+
TOP_BAR_COLOR_ANIMATION__TABS,
78
}
89

910
private val ToggleDefaults = mapOf(
10-
RNNToggles.TOP_BAR_COLOR_ANIMATION to false
11+
RNNToggles.TOP_BAR_COLOR_ANIMATION__PUSH to false,
12+
RNNToggles.TOP_BAR_COLOR_ANIMATION__TABS to false,
1113
)
1214

1315
object RNNFeatureToggles {

lib/android/app/src/main/java/com/reactnativenavigation/NavigationActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import android.annotation.TargetApi;
44
import android.content.Intent;
55
import android.content.res.Configuration;
6-
import android.graphics.Color;
76
import android.os.Build;
87
import android.os.Bundle;
98
import android.view.KeyEvent;
@@ -12,8 +11,8 @@
1211
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
1312
import com.facebook.react.modules.core.PermissionAwareActivity;
1413
import com.facebook.react.modules.core.PermissionListener;
15-
import com.reactnativenavigation.options.Options;
1614
import com.reactnativenavigation.viewcontrollers.overlay.OverlayManager;
15+
import com.reactnativenavigation.viewcontrollers.statusbar.StatusBarPresenter;
1716
import com.reactnativenavigation.viewcontrollers.viewcontroller.RootPresenter;
1817
import com.reactnativenavigation.react.JsDevReloadHandler;
1918
import com.reactnativenavigation.react.ReactGateway;
@@ -51,6 +50,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
5150
navigator.bindViews();
5251
getReactGateway().onActivityCreated(this);
5352
setBackPressedCallback();
53+
StatusBarPresenter.Companion.init(this);
5454
}
5555

5656
@Override

lib/android/app/src/main/java/com/reactnativenavigation/NavigationApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void onCreate() {
5353
* @return a singleton {@link ReactGateway}
5454
*/
5555
protected ReactGateway createReactGateway() {
56-
return new ReactGateway(getReactHost(), getReactNativeHost().getUseDeveloperSupport());
56+
return new ReactGateway(getReactHost(), getReactNativeHost());
5757
}
5858

5959
public ReactGateway getReactGateway() {

lib/android/app/src/main/java/com/reactnativenavigation/options/LayoutFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,17 @@
5151
import org.json.JSONObject;
5252

5353
public class LayoutFactory {
54-
private final ReactHost reactHost;
55-
private Activity activity;
54+
private final ReactHost reactHost;
55+
private Activity activity;
5656
private ChildControllersRegistry childRegistry;
5757
private EventEmitter eventEmitter;
5858
private Map<String, ExternalComponentCreator> externalComponentCreators;
5959
private @NonNull Options defaultOptions = new Options();
6060
private TypefaceLoader typefaceManager;
6161

6262
public LayoutFactory(ReactHost reactHost) {
63-
this.reactHost = reactHost;
64-
}
63+
this.reactHost = reactHost;
64+
}
6565

6666
public void setDefaultOptions(@NonNull Options defaultOptions) {
6767
Assertions.assertNotNull(defaultOptions);

lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationReactInitializer.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,15 @@ void onActivityResumed(NavigationActivity activity) {
3737

3838
void onActivityPaused(NavigationActivity activity) {
3939
isActivityReadyForUi = false;
40-
// TODO: Check it needed
41-
//if (reactHost.hasStartedCreatingInitialContext()) {
4240
reactHost.onHostPause(activity);
43-
//}
4441
}
4542

4643
void onActivityDestroyed(NavigationActivity activity) {
4744
reactHost.removeReactInstanceEventListener(this);
48-
//if (reactHost.gehasStartedCreatingInitialContext()) {
4945
reactHost.onHostDestroy(activity);
50-
//}
5146
}
5247

5348
private void prepareReactApp() {
54-
// TODO: Check if needed
55-
//if (shouldCreateContext()) {
5649
reactHost.start();
5750
if (waitingForAppLaunchEvent) {
5851
if (reactHost.getCurrentReactContext() != null) {

lib/android/app/src/main/java/com/reactnativenavigation/react/ReactView.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,31 +72,31 @@ public void destroy() {
7272

7373
public void sendComponentWillStart(ComponentType type) {
7474
this.post(()->{
75-
ReactContext currentReactContext = getReactContent();
75+
ReactContext currentReactContext = getReactContext();
7676
if (currentReactContext != null)
7777
new EventEmitter(currentReactContext).emitComponentWillAppear(componentId, componentName, type);
7878
});
7979
}
8080

8181
public void sendComponentStart(ComponentType type) {
8282
this.post(()->{
83-
ReactContext currentReactContext = getReactContent();
83+
ReactContext currentReactContext = getReactContext();
8484
if (currentReactContext != null) {
8585
new EventEmitter(currentReactContext).emitComponentDidAppear(componentId, componentName, type);
8686
}
8787
});
8888
}
8989

9090
public void sendComponentStop(ComponentType type) {
91-
ReactContext currentReactContext = getReactContent();
91+
ReactContext currentReactContext = getReactContext();
9292
if (currentReactContext != null) {
9393
new EventEmitter(currentReactContext).emitComponentDidDisappear(componentId, componentName, type);
9494
}
9595
}
9696

9797
@Override
9898
public void sendOnNavigationButtonPressed(String buttonId) {
99-
ReactContext currentReactContext = getReactContent();
99+
ReactContext currentReactContext = getReactContext();
100100
if (currentReactContext != null) {
101101
new EventEmitter(currentReactContext).emitOnNavigationButtonPressed(componentId, buttonId);
102102
}
@@ -121,7 +121,7 @@ public boolean isRendered() {
121121
}
122122

123123
public EventDispatcher getEventDispatcher() {
124-
ReactContext reactContext = getReactContent();
124+
ReactContext reactContext = getReactContext();
125125
return reactContext == null ? null : UIManagerHelper.getEventDispatcher(reactContext, UIManagerType.FABRIC);
126126
}
127127

@@ -134,7 +134,7 @@ private ReactHost getReactHost() {
134134
return ((ReactApplication)getContext().getApplicationContext()).getReactHost();
135135
}
136136

137-
private ReactContext getReactContent() {
137+
private ReactContext getReactContext() {
138138
return getReactHost().getCurrentReactContext();
139139
}
140140
}

lib/android/app/src/main/java/com/reactnativenavigation/utils/ColorUtils.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.reactnativenavigation.utils;
22

3+
import android.graphics.Color;
4+
35
public class ColorUtils {
46
public static double[] colorToLAB(int color) {
57
final double[] result = new double[3];
@@ -10,4 +12,13 @@ public static double[] colorToLAB(int color) {
1012
public static int labToColor(double[] lab) {
1113
return androidx.core.graphics.ColorUtils.LABToColor(lab[0], lab[1], lab[2]);
1214
}
15+
16+
public static boolean isColorLight(int color) {
17+
double darkness = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255;
18+
return darkness < 0.5;
19+
}
20+
21+
public static int setAlpha(int color, int alpha) {
22+
return (color & 0x00FFFFFF) | (alpha << 24);
23+
}
1324
}

lib/android/app/src/main/java/com/reactnativenavigation/utils/SystemUiUtils.kt

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.reactnativenavigation.utils
33
import android.app.Activity
44
import android.graphics.Color
55
import android.graphics.Rect
6-
import android.os.Build
76
import android.view.View
87
import android.view.Window
98
import androidx.annotation.ColorInt
@@ -16,7 +15,6 @@ import kotlin.math.ceil
1615

1716
object SystemUiUtils {
1817
private const val STATUS_BAR_HEIGHT_M = 24
19-
private const val STATUS_BAR_HEIGHT_L = 25
2018
internal const val STATUS_BAR_HEIGHT_TRANSLUCENCY = 0.65f
2119
private var statusBarHeight = -1
2220
var navigationBarDefaultColor = -1
@@ -38,7 +36,7 @@ object SystemUiUtils {
3836
val contentViewTop = contentView.top
3937
abs(contentViewTop - statusBarHeight)
4038
}
41-
} ?: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) STATUS_BAR_HEIGHT_M else STATUS_BAR_HEIGHT_L
39+
} ?: STATUS_BAR_HEIGHT_M
4240
statusBarHeight
4341
}
4442
return res
@@ -77,8 +75,6 @@ object SystemUiUtils {
7775

7876
@JvmStatic
7977
fun setStatusBarColorScheme(window: Window?, view: View, isDark: Boolean) {
80-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return
81-
8278
window?.let {
8379
WindowInsetsControllerCompat(window, view).isAppearanceLightStatusBars = isDark
8480
// Workaround: on devices with api 30 status bar icons flickers or get hidden when removing view
@@ -121,18 +117,17 @@ object SystemUiUtils {
121117
@ColorInt color: Int,
122118
translucent: Boolean
123119
) {
124-
val opaqueColor =
125-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
126-
Color.BLACK
127-
} else {
128-
val colorAlpha = Color.alpha(color)
129-
val alpha = if (translucent && colorAlpha == 255) STATUS_BAR_HEIGHT_TRANSLUCENCY else colorAlpha/255.0f
130-
val red: Int = Color.red(color)
131-
val green: Int = Color.green(color)
132-
val blue: Int = Color.blue(color)
133-
Color.argb(ceil(alpha * 255).toInt(), red, green, blue)
134-
}
135-
window?.statusBarColor = opaqueColor
120+
val colorAlpha = Color.alpha(color)
121+
val alpha = if (translucent && colorAlpha == 255) STATUS_BAR_HEIGHT_TRANSLUCENCY else colorAlpha/255.0f
122+
val red: Int = Color.red(color)
123+
val green: Int = Color.green(color)
124+
val blue: Int = Color.blue(color)
125+
val opaqueColor = Color.argb(ceil(alpha * 255).toInt(), red, green, blue)
126+
setStatusBarColor(window, opaqueColor)
127+
}
128+
129+
fun setStatusBarColor(window: Window?, color: Int) {
130+
window?.statusBarColor = color
136131
}
137132

138133
@JvmStatic

lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabPresenter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import androidx.annotation.NonNull;
1111

12-
import com.aurelhubert.ahbottomnavigation.AHTextView;
1312
import com.aurelhubert.ahbottomnavigation.notification.AHNotification;
1413
import com.reactnativenavigation.options.BottomTabOptions;
1514
import com.reactnativenavigation.options.DotIndicatorOptions;

0 commit comments

Comments
 (0)