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
[splash-screen] Fix reading splash image from the android.splash config #10494
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -10,6 +10,7 @@ import org.json.JSONObject | |||||||||||||||||||||||||||||||||||||||||||||||||||
class ManagedAppSplashScreenConfiguration private constructor() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
var resizeMode: SplashScreenImageResizeMode = SplashScreenImageResizeMode.CONTAIN | ||||||||||||||||||||||||||||||||||||||||||||||||||||
private set | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
@ColorInt | ||||||||||||||||||||||||||||||||||||||||||||||||||||
var backgroundColor = Color.parseColor("#ffffff") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
private set | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -36,7 +37,7 @@ class ManagedAppSplashScreenConfiguration private constructor() { | |||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
private fun parseResizeMode(manifest: JSONObject): SplashScreenImageResizeMode? { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
val resizeMode = getStringFromManifest( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
val resizeMode = getStringFromJSONObject( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
manifest, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
arrayOf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
ExponentManifest.MANIFEST_ANDROID_INFO_KEY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -52,7 +53,7 @@ class ManagedAppSplashScreenConfiguration private constructor() { | |||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
private fun parseBackgroundColor(manifest: JSONObject): Int? { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
val backgroundColor = getStringFromManifest( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
val backgroundColor = getStringFromJSONObject( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
manifest, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
arrayOf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
ExponentManifest.MANIFEST_ANDROID_INFO_KEY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -69,8 +70,30 @@ class ManagedAppSplashScreenConfiguration private constructor() { | |||||||||||||||||||||||||||||||||||||||||||||||||||
} else null | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||
* Tries to retrieve imageUrl from the manifest checking for value for keys/paths in following order | ||||||||||||||||||||||||||||||||||||||||||||||||||||
* - android-scoped splash dpi images (starting from 'xxx-hdpi" and ending with 'mdpi') | ||||||||||||||||||||||||||||||||||||||||||||||||||||
* - android-scoped splash imageUrl | ||||||||||||||||||||||||||||||||||||||||||||||||||||
* - generic splash imageUrl | ||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
private fun parseImageUrl(manifest: JSONObject): String? { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
return getStringFromManifest( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
val androidSplash = manifest | ||||||||||||||||||||||||||||||||||||||||||||||||||||
.optJSONObject(ExponentManifest.MANIFEST_ANDROID_INFO_KEY) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
?.optJSONObject(ExponentManifest.MANIFEST_SPLASH_INFO_KEY) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
if (androidSplash != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
val dpiRelatedImageUrl = getStringFromJSONObject( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So… would this return the first non-empty value for any of the keys defined in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've been always doing this that way (code from the expo/android/expoview/src/main/java/host/exp/exponent/LoadingView.java Lines 271 to 295 in 9db4ea6
The image is fetched into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah so this won't be used in standalone apps, sorry. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if it's the way we've always done it then let's stick with that. we can follow up with improvements over status quo if needed in another pr |
||||||||||||||||||||||||||||||||||||||||||||||||||||
androidSplash, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
*arrayOf("xxxhdpi", "xxhdpi", "xhdpi", "hdpi", "mdpi" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
.map { s -> "${s}Url" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
.map { s -> arrayOf(s) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
.toTypedArray()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
if (dpiRelatedImageUrl != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
return dpiRelatedImageUrl | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
return getStringFromJSONObject( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
manifest, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
arrayOf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
ExponentManifest.MANIFEST_ANDROID_INFO_KEY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -84,18 +107,18 @@ class ManagedAppSplashScreenConfiguration private constructor() { | |||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
private fun getStringFromManifest(manifest: JSONObject, vararg paths: Array<String>): String? { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
private fun getStringFromJSONObject(jsonObject: JSONObject, vararg paths: Array<String>): String? { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
for (path in paths) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
val pathResult = getStringFromManifest(manifest, path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
val pathResult = getStringFromJSONObject(jsonObject, path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
if (pathResult != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
return pathResult | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
return null | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
private fun getStringFromManifest(manifest: JSONObject, path: Array<String>): String? { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
var json: JSONObject? = manifest | ||||||||||||||||||||||||||||||||||||||||||||||||||||
private fun getStringFromJSONObject(jsonObject: JSONObject, path: Array<String>): String? { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
var json: JSONObject? = jsonObject | ||||||||||||||||||||||||||||||||||||||||||||||||||||
for (i in path.indices) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
val isLastKey = i == path.size - 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
val key = path[i] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what was the motivation for moving this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
config
variable is only used in theif
block, os it was just natural for me to scope it intoif
block as well 🤷There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, ok. i just wasn't sure if it was somehow intended to be related to the fix