From 94573900225d6d800a6e97601fdf9bb5410a8692 Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Fri, 13 Aug 2021 11:59:32 +0300 Subject: [PATCH 01/14] add native colors --- .../android/app/src/main/res/values-night/colors.xml | 5 +++++ .../android/app/src/main/res/values-notnight/colors.xml | 5 +++++ playground/android/app/src/main/res/values/colors.xml | 5 +++++ playground/android/app/src/main/res/values/styles.xml | 7 +------ 4 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 playground/android/app/src/main/res/values-night/colors.xml create mode 100644 playground/android/app/src/main/res/values-notnight/colors.xml create mode 100644 playground/android/app/src/main/res/values/colors.xml diff --git a/playground/android/app/src/main/res/values-night/colors.xml b/playground/android/app/src/main/res/values-night/colors.xml new file mode 100644 index 00000000000..0d7bbf0c4e9 --- /dev/null +++ b/playground/android/app/src/main/res/values-night/colors.xml @@ -0,0 +1,5 @@ + + + #BA292E + #282528 + \ No newline at end of file diff --git a/playground/android/app/src/main/res/values-notnight/colors.xml b/playground/android/app/src/main/res/values-notnight/colors.xml new file mode 100644 index 00000000000..a57d4024920 --- /dev/null +++ b/playground/android/app/src/main/res/values-notnight/colors.xml @@ -0,0 +1,5 @@ + + + #000000 + #e8e8e8 + \ No newline at end of file diff --git a/playground/android/app/src/main/res/values/colors.xml b/playground/android/app/src/main/res/values/colors.xml new file mode 100644 index 00000000000..a57d4024920 --- /dev/null +++ b/playground/android/app/src/main/res/values/colors.xml @@ -0,0 +1,5 @@ + + + #000000 + #e8e8e8 + \ No newline at end of file diff --git a/playground/android/app/src/main/res/values/styles.xml b/playground/android/app/src/main/res/values/styles.xml index 31533f92037..94332181468 100644 --- a/playground/android/app/src/main/res/values/styles.xml +++ b/playground/android/app/src/main/res/values/styles.xml @@ -2,11 +2,6 @@ - - - #e8e8e8 \ No newline at end of file From a92302ef3b60e6193b871976cbd6556ff07e2dcc Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Fri, 13 Aug 2021 12:00:19 +0300 Subject: [PATCH 02/14] Update styles.xml --- playground/android/app/src/main/res/values/styles.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/playground/android/app/src/main/res/values/styles.xml b/playground/android/app/src/main/res/values/styles.xml index 94332181468..7879f972437 100644 --- a/playground/android/app/src/main/res/values/styles.xml +++ b/playground/android/app/src/main/res/values/styles.xml @@ -2,6 +2,5 @@ \ No newline at end of file From da091673df4eafdba0e5fb480c62565d1dd727b2 Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Fri, 13 Aug 2021 12:00:34 +0300 Subject: [PATCH 03/14] use textColor as an example of platform color --- playground/src/commons/Colors.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/playground/src/commons/Colors.ts b/playground/src/commons/Colors.ts index 166b485cf9e..5bd9462e51d 100644 --- a/playground/src/commons/Colors.ts +++ b/playground/src/commons/Colors.ts @@ -1,10 +1,12 @@ +import { PlatformColor } from 'react-native'; + const colors = { background: { light: '#e8e8e8', dark: '#282528' }, barBackground: { light: 'white', dark: '#282528' }, primary: { light: '#5847ff', dark: '#BA292E' }, secondary: { light: '#FFC249', dark: '#5847ff' }, accent: { light: '#65C888', dark: '#FFA73C' }, - textColor: { light: 'black', dark: '#BA292E' }, + textColor: PlatformColor('@color/textColor'), activeTextColor: { light: '#5847ff', dark: '#FFA73C' }, iconTint: { light: 'black', dark: '#BA292E' }, activeIconTint: { light: '#5847ff', dark: '#FFA73C' }, From a7562777670fedbee280932868c6fb1e18fa31e4 Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Fri, 13 Aug 2021 12:00:48 +0300 Subject: [PATCH 04/14] extend Color type --- lib/src/interfaces/Options.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/interfaces/Options.ts b/lib/src/interfaces/Options.ts index 3cf8e3298d7..7f8cccfc64d 100644 --- a/lib/src/interfaces/Options.ts +++ b/lib/src/interfaces/Options.ts @@ -1,9 +1,9 @@ // tslint:disable jsdoc-format -import { ImageRequireSource, ImageSourcePropType, Insets } from 'react-native'; +import { ImageRequireSource, ImageSourcePropType, Insets, OpaqueColorValue } from 'react-native'; // TODO: Import ColorValue instead when upgrading @types/react-native to 0.63+ // Only assign PlatformColor or DynamicColorIOS as a Color symbol! -export declare type Color = string | symbol | ThemeColor | null; +export declare type Color = string | symbol | ThemeColor | OpaqueColorValue | null; type FontFamily = string; type FontStyle = 'normal' | 'italic'; type FontWeightIOS = From 5d866fb1d31d3c713755791d70b426d6e50ae583 Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Fri, 13 Aug 2021 12:03:01 +0300 Subject: [PATCH 05/14] bypass platform color --- lib/src/commands/OptionsProcessor.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/src/commands/OptionsProcessor.ts b/lib/src/commands/OptionsProcessor.ts index 43d48c9a0a5..0b4950b972f 100644 --- a/lib/src/commands/OptionsProcessor.ts +++ b/lib/src/commands/OptionsProcessor.ts @@ -120,10 +120,15 @@ export class OptionsProcessor { if (value === null) { options[key] = newColorObj; } else if (value instanceof Object) { - for (let keyColor in value) { - newColorObj[keyColor] = this.colorService.toNativeColor(value[keyColor]); + //may check type of PlatformColor result + if ('resource_paths' in value) { + options[key] = value; + } else { + for (let keyColor in value) { + newColorObj[keyColor] = this.colorService.toNativeColor(value[keyColor]); + } + options[key] = newColorObj; } - options[key] = newColorObj; } else { let parsedColor = this.colorService.toNativeColor(value); newColorObj.light = parsedColor; From af599f11a2f993b79210b031b9ea5450e1b60d84 Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Fri, 13 Aug 2021 12:03:26 +0300 Subject: [PATCH 06/14] Update Colors.ts --- playground/src/commons/Colors.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/playground/src/commons/Colors.ts b/playground/src/commons/Colors.ts index 5bd9462e51d..8fb43510437 100644 --- a/playground/src/commons/Colors.ts +++ b/playground/src/commons/Colors.ts @@ -1,4 +1,4 @@ -import { PlatformColor } from 'react-native'; +import { Platform, PlatformColor } from 'react-native'; const colors = { background: { light: '#e8e8e8', dark: '#282528' }, @@ -6,7 +6,8 @@ const colors = { primary: { light: '#5847ff', dark: '#BA292E' }, secondary: { light: '#FFC249', dark: '#5847ff' }, accent: { light: '#65C888', dark: '#FFA73C' }, - textColor: PlatformColor('@color/textColor'), + textColor: + Platform.OS === 'ios' ? PlatformColor('placeholderText') : PlatformColor('@color/textColor'), activeTextColor: { light: '#5847ff', dark: '#FFA73C' }, iconTint: { light: 'black', dark: '#BA292E' }, activeIconTint: { light: '#5847ff', dark: '#FFA73C' }, From 13bd53d9cd7eb34198298b97fc0c229f34320439 Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Fri, 13 Aug 2021 12:22:59 +0300 Subject: [PATCH 07/14] add sanity test --- .../options/parsers/JSONParser.java | 5 ++- .../com/reactnativenavigation/BaseTest.java | 3 ++ .../options/parsers/ColorParseTest.java | 37 +++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/parsers/JSONParser.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/parsers/JSONParser.java index 09b91606ed5..68f0195cb52 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/parsers/JSONParser.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/parsers/JSONParser.java @@ -1,5 +1,6 @@ package com.reactnativenavigation.options.parsers; +import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.ReadableMapKeySetIterator; @@ -98,7 +99,7 @@ private static Object parseNumber(ReadableArray arr, int index) { } public static WritableMap convert(JSONObject jsonObject) { - WritableMap map = new WritableNativeMap(); + WritableMap map = Arguments.createMap(); Iterator iterator = jsonObject.keys(); while (iterator.hasNext()) { @@ -125,7 +126,7 @@ public static WritableMap convert(JSONObject jsonObject) { } public static WritableArray convert(JSONArray jsonArray) { - WritableArray array = new WritableNativeArray(); + WritableArray array = Arguments.createArray(); for (int i = 0; i < jsonArray.length(); i++) { Object value = jsonArray.opt(i); diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/BaseTest.java b/lib/android/app/src/test/java/com/reactnativenavigation/BaseTest.java index 8f40592464d..9fa16173771 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/BaseTest.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/BaseTest.java @@ -5,6 +5,7 @@ import android.content.res.AssetManager; import android.content.res.Configuration; import android.content.res.Resources; +import android.graphics.Color; import android.os.Handler; import android.os.Looper; import android.util.DisplayMetrics; @@ -58,6 +59,8 @@ public void beforeEach() { mockConfiguration.uiMode = Configuration.UI_MODE_NIGHT_NO; when(res.getConfiguration()).thenReturn(mockConfiguration); when(NavigationApplication.instance.getResources()).thenReturn(res); + when(res.getColor(any(Integer.class))).thenReturn(0x00000); + when(res.getColor(any(),any())).thenReturn(0x00000); } public void mockStatusBarUtils(int statusBarHeight,int statusBarHeightDp, Functions.Func block) { diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/options/parsers/ColorParseTest.java b/lib/android/app/src/test/java/com/reactnativenavigation/options/parsers/ColorParseTest.java index 74f99c8673a..b257ef6c5cd 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/options/parsers/ColorParseTest.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/options/parsers/ColorParseTest.java @@ -1,20 +1,57 @@ package com.reactnativenavigation.options.parsers; +import com.facebook.react.bridge.Arguments; +import com.facebook.react.bridge.JavaOnlyArray; +import com.facebook.react.bridge.JavaOnlyMap; import com.reactnativenavigation.BaseTest; import com.reactnativenavigation.options.params.DontApplyColour; +import com.reactnativenavigation.options.params.ReactPlatformColor; +import com.reactnativenavigation.utils.StatusBarUtils; +import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.junit.Test; +import org.mockito.MockedStatic; +import org.mockito.Mockito; import static org.assertj.core.api.Java6Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; + +import android.app.Activity; public class ColorParseTest extends BaseTest { + Activity activity; + @Override + public void beforeEach() { + super.beforeEach(); + activity = newActivity(); + } + @Test public void nullIsParsedAsNoColor() throws JSONException { JSONObject json = new JSONObject(); json.put("color", "NoColor"); assertThat(ColorParser.parse(null, json, "color")).isInstanceOf(DontApplyColour.class); } + + @Test + public void shouldParsePlatformColors() throws JSONException { + JSONObject json = new JSONObject(); + JSONObject color = new JSONObject(); + final JSONArray jsonArray = new JSONArray(); + jsonArray.put("@color/colorPrimary"); + color.put("resource_paths", + jsonArray); + try (MockedStatic theMock = Mockito.mockStatic(Arguments.class)) { + theMock.when(() -> { + Arguments.createMap(); + }).thenReturn(new JavaOnlyMap()); + theMock.when(() -> { + Arguments.createArray(); + }).thenReturn(new JavaOnlyArray()); + assertThat(ColorParser.parse(activity, color, "color")).isInstanceOf(ReactPlatformColor.class); + } + } } From 2b4e872baae453ab451d9a8a45ed8d7021d8ee2e Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Fri, 13 Aug 2021 12:23:34 +0300 Subject: [PATCH 08/14] add Native ReactPlatformColor --- .../options/params/ReactPlatformColor.kt | 23 +++++++++++++++++++ .../options/params/ThemeColour.kt | 15 ++++++++---- .../options/parsers/ColorParser.java | 6 ++++- 3 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 lib/android/app/src/main/java/com/reactnativenavigation/options/params/ReactPlatformColor.kt diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/params/ReactPlatformColor.kt b/lib/android/app/src/main/java/com/reactnativenavigation/options/params/ReactPlatformColor.kt new file mode 100644 index 00000000000..5850dc0ca21 --- /dev/null +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/params/ReactPlatformColor.kt @@ -0,0 +1,23 @@ +package com.reactnativenavigation.options.params + +import com.facebook.react.bridge.ColorPropConverter +import com.facebook.react.bridge.ReadableMap +import com.reactnativenavigation.NavigationApplication + +private fun parsePlatformColor(paths: ReadableMap) = + ColorPropConverter.getColor(paths, NavigationApplication.instance) + +class ReactPlatformColor(private val paths: ReadableMap) : + Colour(parsePlatformColor(paths)) { + override fun get(): Int { + return parsePlatformColor(paths) + } + + override fun get(defaultValue: Int?): Int? { + return try { + parsePlatformColor(paths) + }catch (e:Exception){ + defaultValue + } + } +} \ No newline at end of file diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/params/ThemeColour.kt b/lib/android/app/src/main/java/com/reactnativenavigation/options/params/ThemeColour.kt index 5784199b150..0096cc87a20 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/params/ThemeColour.kt +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/params/ThemeColour.kt @@ -18,7 +18,7 @@ class NullThemeColour() : ThemeColour(NullColor(), NullColor()) { open class ThemeColour(private var lightColor: Colour, private var darkColor: Colour) { - constructor(color:Colour):this(color,color) + constructor(color: Colour) : this(color, color) private fun selectedColor() = if (isDarkMode()) darkColor else lightColor @@ -30,18 +30,23 @@ open class ThemeColour(private var lightColor: Colour, private var darkColor: Co fun hasTransparency() = selectedColor().hasTransparency() fun canApplyValue() = selectedColor().canApplyValue() - companion object{ + companion object { @JvmStatic - fun of(color:Int) = ThemeColour(Colour(color), Colour(color)) + fun of(color: Int) = ThemeColour(Colour(color), Colour(color)) + @JvmStatic - fun of(light:Int,dark:Int) = ThemeColour(Colour(light),Colour(dark)) + fun of(light: Int, dark: Int) = ThemeColour(Colour(light), Colour(dark)) @JvmStatic fun parse(context: Context, json: JSONObject?): ThemeColour { return json?.let { - ThemeColour(ColorParser.parse(context, json, LIGHT_COLOR_KEY), ColorParser.parse(context, json, DARK_COLOR_KEY)) + ThemeColour( + ColorParser.parse(context, json, LIGHT_COLOR_KEY), + ColorParser.parse(context, json, DARK_COLOR_KEY) + ) } ?: NullThemeColour() } + @JvmStatic fun transparent() = of(Color.TRANSPARENT) diff --git a/lib/android/app/src/reactNative63/java/com/reactnativenavigation/options/parsers/ColorParser.java b/lib/android/app/src/reactNative63/java/com/reactnativenavigation/options/parsers/ColorParser.java index cf059ed2ba2..ca032a0228a 100644 --- a/lib/android/app/src/reactNative63/java/com/reactnativenavigation/options/parsers/ColorParser.java +++ b/lib/android/app/src/reactNative63/java/com/reactnativenavigation/options/parsers/ColorParser.java @@ -6,12 +6,16 @@ import com.reactnativenavigation.options.params.Colour; import com.reactnativenavigation.options.params.DontApplyColour; import com.reactnativenavigation.options.params.NullColor; +import com.reactnativenavigation.options.params.ReactPlatformColor; import org.json.JSONObject; public class ColorParser { public static Colour parse(Context context, JSONObject json, String colorName) { - if (json.has(colorName)) { + if(json.has("resource_paths")){ + return new ReactPlatformColor(JSONParser.convert(json)); + } + else if (json.has(colorName)) { Object color = json.opt(colorName); if (color == null) { return new DontApplyColour(); From 9c6d5db9a51b214e83650456c20a01588e9bc392 Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Mon, 16 Aug 2021 13:57:57 +0300 Subject: [PATCH 09/14] fix tests --- .../options/parsers/ColorParser.java | 36 ------------------ .../options/parsers/ColorParser.kt | 38 +++++++++++++++++++ .../com/reactnativenavigation/BaseTest.java | 5 ++- .../options/parsers/ColorParseTest.java | 8 +--- 4 files changed, 43 insertions(+), 44 deletions(-) delete mode 100644 lib/android/app/src/reactNative63/java/com/reactnativenavigation/options/parsers/ColorParser.java create mode 100644 lib/android/app/src/reactNative63/java/com/reactnativenavigation/options/parsers/ColorParser.kt diff --git a/lib/android/app/src/reactNative63/java/com/reactnativenavigation/options/parsers/ColorParser.java b/lib/android/app/src/reactNative63/java/com/reactnativenavigation/options/parsers/ColorParser.java deleted file mode 100644 index ca032a0228a..00000000000 --- a/lib/android/app/src/reactNative63/java/com/reactnativenavigation/options/parsers/ColorParser.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.reactnativenavigation.options.parsers; - -import android.content.Context; - -import com.facebook.react.bridge.ColorPropConverter; -import com.reactnativenavigation.options.params.Colour; -import com.reactnativenavigation.options.params.DontApplyColour; -import com.reactnativenavigation.options.params.NullColor; -import com.reactnativenavigation.options.params.ReactPlatformColor; - -import org.json.JSONObject; - -public class ColorParser { - public static Colour parse(Context context, JSONObject json, String colorName) { - if(json.has("resource_paths")){ - return new ReactPlatformColor(JSONParser.convert(json)); - } - else if (json.has(colorName)) { - Object color = json.opt(colorName); - if (color == null) { - return new DontApplyColour(); - } else if (color instanceof Integer) { - return new Colour(json.optInt(colorName)); - } - if (color.equals("NoColor")) { - return new DontApplyColour(); - } - Object convertedColor = JSONParser.convert(json.optJSONObject(colorName)); - Integer processedColor = ColorPropConverter.getColor(convertedColor, context); - if (processedColor != null) { - return new Colour(processedColor); - } - } - return new NullColor(); - } -} diff --git a/lib/android/app/src/reactNative63/java/com/reactnativenavigation/options/parsers/ColorParser.kt b/lib/android/app/src/reactNative63/java/com/reactnativenavigation/options/parsers/ColorParser.kt new file mode 100644 index 00000000000..857af348911 --- /dev/null +++ b/lib/android/app/src/reactNative63/java/com/reactnativenavigation/options/parsers/ColorParser.kt @@ -0,0 +1,38 @@ +package com.reactnativenavigation.options.parsers + +import android.content.Context +import com.facebook.react.bridge.ColorPropConverter +import com.reactnativenavigation.options.params.Colour +import com.reactnativenavigation.options.params.DontApplyColour +import com.reactnativenavigation.options.params.NullColor +import com.reactnativenavigation.options.params.ReactPlatformColor +import org.json.JSONObject + +object ColorParser { + private const val KEY_RESOURCE_PATHS = "resource_paths" + private const val VAL_NO_COLOR = "NoColor" + + @JvmStatic + fun parse(context: Context?, json: JSONObject, colorName: String?): Colour { + if (json.has(KEY_RESOURCE_PATHS)) { + return ReactPlatformColor(JSONParser.convert(json)) + } + return when (val color = json.opt(colorName)) { + null, VAL_NO_COLOR -> { + DontApplyColour() + } + is Int -> { + Colour(json.optInt(colorName)) + } + is JSONObject -> { + ColorPropConverter.getColor(color, context)?.let { + Colour(it) + } ?: NullColor() + } + else -> { + NullColor() + } + } + + } +} \ No newline at end of file diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/BaseTest.java b/lib/android/app/src/test/java/com/reactnativenavigation/BaseTest.java index 9fa16173771..50b30e922ce 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/BaseTest.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/BaseTest.java @@ -21,6 +21,7 @@ import org.junit.After; import org.junit.Before; import org.junit.runner.RunWith; +import org.mockito.ArgumentMatchers; import org.mockito.MockedStatic; import org.mockito.Mockito; import org.robolectric.Robolectric; @@ -59,8 +60,8 @@ public void beforeEach() { mockConfiguration.uiMode = Configuration.UI_MODE_NIGHT_NO; when(res.getConfiguration()).thenReturn(mockConfiguration); when(NavigationApplication.instance.getResources()).thenReturn(res); - when(res.getColor(any(Integer.class))).thenReturn(0x00000); - when(res.getColor(any(),any())).thenReturn(0x00000); + when(res.getColor(ArgumentMatchers.anyInt())).thenReturn(0x00000); + when(res.getColor(ArgumentMatchers.anyInt(),any())).thenReturn(0x00000); } public void mockStatusBarUtils(int statusBarHeight,int statusBarHeightDp, Functions.Func block) { diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/options/parsers/ColorParseTest.java b/lib/android/app/src/test/java/com/reactnativenavigation/options/parsers/ColorParseTest.java index b257ef6c5cd..136fcf8cc5c 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/options/parsers/ColorParseTest.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/options/parsers/ColorParseTest.java @@ -45,12 +45,8 @@ public void shouldParsePlatformColors() throws JSONException { color.put("resource_paths", jsonArray); try (MockedStatic theMock = Mockito.mockStatic(Arguments.class)) { - theMock.when(() -> { - Arguments.createMap(); - }).thenReturn(new JavaOnlyMap()); - theMock.when(() -> { - Arguments.createArray(); - }).thenReturn(new JavaOnlyArray()); + theMock.when(Arguments::createMap).thenReturn(new JavaOnlyMap()); + theMock.when(Arguments::createArray).thenReturn(new JavaOnlyArray()); assertThat(ColorParser.parse(activity, color, "color")).isInstanceOf(ReactPlatformColor.class); } } From 37b646e9f0f565140a05d1c33035c0c285ac397b Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Mon, 16 Aug 2021 14:53:15 +0300 Subject: [PATCH 10/14] Update OptionsProcessor.test.ts --- lib/src/commands/OptionsProcessor.test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/src/commands/OptionsProcessor.test.ts b/lib/src/commands/OptionsProcessor.test.ts index 6c65519ca4d..defc886f284 100644 --- a/lib/src/commands/OptionsProcessor.test.ts +++ b/lib/src/commands/OptionsProcessor.test.ts @@ -462,6 +462,23 @@ describe('navigation options', () => { Platform.OS = 'android'; }); + it('PlatformColor should be passed to native as is', () => { + const options: Options = { + topBar: { + background: { + color: { + // @ts-ignore + resource_paths: ['@color/textColor'], + }, + }, + }, + }; + uut.processOptions(options, CommandName.SetRoot); + expect(options).toEqual({ + topBar: { background: { color: { resource_paths: ['@color/textColor'] } } }, + }); + }); + it('processes color keys', () => { const options: Options = { statusBar: { backgroundColor: 'red' }, From 2a5ff16945060d8d48c5687ff49491cd7da93fe7 Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Mon, 16 Aug 2021 14:53:29 +0300 Subject: [PATCH 11/14] Update OptionsProcessor.ts --- lib/src/commands/OptionsProcessor.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/src/commands/OptionsProcessor.ts b/lib/src/commands/OptionsProcessor.ts index 0b4950b972f..20af2b67f68 100644 --- a/lib/src/commands/OptionsProcessor.ts +++ b/lib/src/commands/OptionsProcessor.ts @@ -120,7 +120,6 @@ export class OptionsProcessor { if (value === null) { options[key] = newColorObj; } else if (value instanceof Object) { - //may check type of PlatformColor result if ('resource_paths' in value) { options[key] = value; } else { From df117842edbd797e2a3476da40acc863f5d311f4 Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Mon, 16 Aug 2021 18:22:06 +0300 Subject: [PATCH 12/14] add ios support --- lib/src/commands/OptionsProcessor.ts | 5 +- .../rnnTextColor.colorset/Contents.json | 51 +++++++++++++++++++ .../ios/playground/LaunchScreen.storyboard | 22 +++++--- playground/src/commons/Colors.ts | 2 +- 4 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 playground/ios/playground/Images.xcassets/rnnTextColor.colorset/Contents.json diff --git a/lib/src/commands/OptionsProcessor.ts b/lib/src/commands/OptionsProcessor.ts index 20af2b67f68..8f6d508354c 100644 --- a/lib/src/commands/OptionsProcessor.ts +++ b/lib/src/commands/OptionsProcessor.ts @@ -120,8 +120,11 @@ export class OptionsProcessor { if (value === null) { options[key] = newColorObj; } else if (value instanceof Object) { - if ('resource_paths' in value) { + if ('semantic' in value || 'resource_paths' in value) { + console.log(`PlatformColorXXXx key:${key}, val${JSON.stringify(value)}`); + options[key] = value; + return; } else { for (let keyColor in value) { newColorObj[keyColor] = this.colorService.toNativeColor(value[keyColor]); diff --git a/playground/ios/playground/Images.xcassets/rnnTextColor.colorset/Contents.json b/playground/ios/playground/Images.xcassets/rnnTextColor.colorset/Contents.json new file mode 100644 index 00000000000..634c45cab69 --- /dev/null +++ b/playground/ios/playground/Images.xcassets/rnnTextColor.colorset/Contents.json @@ -0,0 +1,51 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0.000", + "green" : "0.000", + "red" : "0.000" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "light" + } + ], + "color" : { + "platform" : "ios", + "reference" : "darkTextColor" + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0.180", + "green" : "0.160", + "red" : "0.730" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/playground/ios/playground/LaunchScreen.storyboard b/playground/ios/playground/LaunchScreen.storyboard index d6b5e4b687e..2b8552ecb68 100644 --- a/playground/ios/playground/LaunchScreen.storyboard +++ b/playground/ios/playground/LaunchScreen.storyboard @@ -1,9 +1,10 @@ - + - + + @@ -19,26 +20,26 @@ - - + - + - + + @@ -46,4 +47,9 @@ + + + + + diff --git a/playground/src/commons/Colors.ts b/playground/src/commons/Colors.ts index 8fb43510437..58737be604d 100644 --- a/playground/src/commons/Colors.ts +++ b/playground/src/commons/Colors.ts @@ -7,7 +7,7 @@ const colors = { secondary: { light: '#FFC249', dark: '#5847ff' }, accent: { light: '#65C888', dark: '#FFA73C' }, textColor: - Platform.OS === 'ios' ? PlatformColor('placeholderText') : PlatformColor('@color/textColor'), + Platform.OS === 'ios' ? PlatformColor('labelColor') : PlatformColor('@color/textColor'), activeTextColor: { light: '#5847ff', dark: '#FFA73C' }, iconTint: { light: 'black', dark: '#BA292E' }, activeIconTint: { light: '#5847ff', dark: '#FFA73C' }, From 299136d9294c275e641714c9c90d323e62a2bc26 Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Mon, 16 Aug 2021 18:26:17 +0300 Subject: [PATCH 13/14] Update OptionsProcessor.ts --- lib/src/commands/OptionsProcessor.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/src/commands/OptionsProcessor.ts b/lib/src/commands/OptionsProcessor.ts index 8f6d508354c..4023736c0c9 100644 --- a/lib/src/commands/OptionsProcessor.ts +++ b/lib/src/commands/OptionsProcessor.ts @@ -121,8 +121,6 @@ export class OptionsProcessor { options[key] = newColorObj; } else if (value instanceof Object) { if ('semantic' in value || 'resource_paths' in value) { - console.log(`PlatformColorXXXx key:${key}, val${JSON.stringify(value)}`); - options[key] = value; return; } else { From db36d6509cd95e2589b35c77a72015f9cf2f2b37 Mon Sep 17 00:00:00 2001 From: Yogev Ben David Date: Sun, 29 Aug 2021 14:28:03 +0300 Subject: [PATCH 14/14] Use color object as custom platform colors isn't supported on iOS --- playground/src/commons/Colors.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/playground/src/commons/Colors.ts b/playground/src/commons/Colors.ts index 58737be604d..608e0f53963 100644 --- a/playground/src/commons/Colors.ts +++ b/playground/src/commons/Colors.ts @@ -7,7 +7,9 @@ const colors = { secondary: { light: '#FFC249', dark: '#5847ff' }, accent: { light: '#65C888', dark: '#FFA73C' }, textColor: - Platform.OS === 'ios' ? PlatformColor('labelColor') : PlatformColor('@color/textColor'), + Platform.OS === 'ios' + ? { light: '#5847ff', dark: '#BA292E' } + : PlatformColor('@color/textColor'), activeTextColor: { light: '#5847ff', dark: '#FFA73C' }, iconTint: { light: 'black', dark: '#BA292E' }, activeIconTint: { light: '#5847ff', dark: '#FFA73C' },