forked from wix/react-native-navigation
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Following the discussion here: wix#6618. ## Android - Colours are parsed natively. - Creating custom colour when a PlatformColor is passed to native. - Both light/dark values have the same res attribute resolved when `get` is called. ## IOS - Added a custom colour. - Changed storyboard splash screen. - Using `labelColor` as a test. CC: @yogevbd closes: wix#6618 Co-authored-by: Yogev Ben David <yogev132@gmail.com>
- Loading branch information
Showing
17 changed files
with
224 additions
and
59 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
lib/android/app/src/main/java/com/reactnativenavigation/options/params/ReactPlatformColor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 0 additions & 32 deletions
32
...oid/app/src/reactNative63/java/com/reactnativenavigation/options/parsers/ColorParser.java
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
...droid/app/src/reactNative63/java/com/reactnativenavigation/options/parsers/ColorParser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
lib/android/app/src/test/java/com/reactnativenavigation/options/parsers/ColorParseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,53 @@ | ||
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<Arguments> 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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<item name="textColor" type="color">#BA292E</item> | ||
<item name="backgroundColor" type="color">#282528</item> | ||
</resources> |
5 changes: 5 additions & 0 deletions
5
playground/android/app/src/main/res/values-notnight/colors.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<item name="textColor" type="color">#000000</item> | ||
<item name="backgroundColor" type="color">#e8e8e8</item> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<item name="textColor" type="color">#000000</item> | ||
<item name="backgroundColor" type="color">#e8e8e8</item> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
playground/ios/playground/Images.xcassets/rnnTextColor.colorset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
Oops, something went wrong.