-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This feature allows adding insets to the topmost view controller in the hierarchy, it is useful for presenting a banner across the app with overlay without having to re-render it each time a new screen is being pushed. Co-authored-by: Ward Abbass <swabbass@gmail.com>
- Loading branch information
Showing
33 changed files
with
490 additions
and
81 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,11 @@ | ||
import { execSync } from 'shell-utils/src/exec'; | ||
|
||
const utils = { | ||
setDemoMode: () => { | ||
execSync( | ||
'xcrun simctl status_bar "iPhone 11" override --time "12:00" --batteryState charged --batteryLevel 100 --wifiBars 3 --cellularMode active --cellularBars 4' | ||
); | ||
}, | ||
}; | ||
|
||
export default utils; |
48 changes: 0 additions & 48 deletions
48
lib/android/app/src/main/java/com/reactnativenavigation/options/LayoutOptions.java
This file was deleted.
Oops, something went wrong.
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
44 changes: 44 additions & 0 deletions
44
lib/android/app/src/main/java/com/reactnativenavigation/options/layout/LayoutInsets.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,44 @@ | ||
package com.reactnativenavigation.options.layout | ||
|
||
import com.reactnativenavigation.utils.dp | ||
import org.json.JSONObject | ||
|
||
class LayoutInsets( | ||
var top: Int?=null, | ||
var left: Int?=null, | ||
var bottom: Int?=null, | ||
var right: Int?=null | ||
) { | ||
fun merge(toMerge: LayoutInsets?, defaults: LayoutInsets?) { | ||
toMerge?.let { options-> | ||
options.top?.let { this.top = it } | ||
options.bottom?.let { this.bottom = it } | ||
options.left?.let { this.left = it } | ||
options.right?.let { this.right = it } | ||
} | ||
|
||
defaults?.let { | ||
options-> | ||
top = top?:options.top | ||
left = left?:options.left | ||
right = right?:options.right | ||
bottom = bottom?:options.bottom | ||
} | ||
} | ||
|
||
companion object{ | ||
fun parse(jsonObject: JSONObject?): LayoutInsets { | ||
return LayoutInsets( | ||
jsonObject?.optInt("top")?.dp, | ||
jsonObject?.optInt("left")?.dp, | ||
jsonObject?.optInt("bottom")?.dp, | ||
jsonObject?.optInt("right")?.dp | ||
) | ||
} | ||
} | ||
|
||
fun hasValue(): Boolean { | ||
return top!=null || bottom!=null || left!=null || right!=null | ||
} | ||
|
||
} |
71 changes: 71 additions & 0 deletions
71
lib/android/app/src/main/java/com/reactnativenavigation/options/layout/LayoutOptions.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,71 @@ | ||
package com.reactnativenavigation.options.layout | ||
|
||
import android.content.Context | ||
import com.reactnativenavigation.options.LayoutDirection | ||
import com.reactnativenavigation.options.OrientationOptions | ||
import com.reactnativenavigation.options.params.* | ||
import com.reactnativenavigation.options.params.Number | ||
import com.reactnativenavigation.options.parsers.BoolParser | ||
import com.reactnativenavigation.options.parsers.NumberParser | ||
import org.json.JSONObject | ||
|
||
class LayoutOptions { | ||
@JvmField | ||
var backgroundColor: ThemeColour = NullThemeColour() | ||
|
||
@JvmField | ||
var componentBackgroundColor: ThemeColour = NullThemeColour() | ||
|
||
@JvmField | ||
var topMargin: Number = NullNumber() | ||
|
||
@JvmField | ||
var adjustResize: Bool = NullBool() | ||
|
||
@JvmField | ||
var orientation = OrientationOptions() | ||
|
||
@JvmField | ||
var direction = LayoutDirection.DEFAULT | ||
|
||
var insets: LayoutInsets = LayoutInsets() | ||
|
||
|
||
fun mergeWith(other: LayoutOptions) { | ||
if (other.backgroundColor.hasValue()) backgroundColor = other.backgroundColor | ||
if (other.componentBackgroundColor.hasValue()) componentBackgroundColor = other.componentBackgroundColor | ||
if (other.topMargin.hasValue()) topMargin = other.topMargin | ||
if (other.orientation.hasValue()) orientation = other.orientation | ||
if (other.direction.hasValue()) direction = other.direction | ||
if (other.adjustResize.hasValue()) adjustResize = other.adjustResize | ||
insets.merge(other.insets, null) | ||
} | ||
|
||
fun mergeWithDefault(defaultOptions: LayoutOptions) { | ||
if (!backgroundColor.hasValue()) backgroundColor = defaultOptions.backgroundColor | ||
if (!componentBackgroundColor.hasValue()) componentBackgroundColor = defaultOptions.componentBackgroundColor | ||
if (!topMargin.hasValue()) topMargin = defaultOptions.topMargin | ||
if (!orientation.hasValue()) orientation = defaultOptions.orientation | ||
if (!direction.hasValue()) direction = defaultOptions.direction | ||
if (!adjustResize.hasValue()) adjustResize = defaultOptions.adjustResize | ||
insets.merge(null, defaultOptions.insets) | ||
|
||
} | ||
|
||
companion object { | ||
@JvmStatic | ||
fun parse(context: Context?, json: JSONObject?): LayoutOptions { | ||
val result = LayoutOptions() | ||
if (json == null) return result | ||
result.backgroundColor = ThemeColour.parse(context!!, json.optJSONObject("backgroundColor")) | ||
result.componentBackgroundColor = ThemeColour.parse(context, json.optJSONObject("componentBackgroundColor")) | ||
result.topMargin = NumberParser.parse(json, "topMargin") | ||
result.insets = LayoutInsets.parse(json.optJSONObject("insets")) | ||
result.orientation = OrientationOptions.parse(json) | ||
result.direction = LayoutDirection.fromString(json.optString("direction", "")) | ||
result.adjustResize = BoolParser.parse(json, "adjustResize") | ||
return result | ||
} | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
lib/android/app/src/main/java/com/reactnativenavigation/utils/PrimitiveExt.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,9 @@ | ||
package com.reactnativenavigation.utils | ||
|
||
import android.content.res.Resources | ||
|
||
val Int.dp: Int | ||
get() = (this * Resources.getSystem().displayMetrics.density).toInt() | ||
|
||
val Float.dp: Int | ||
get() = (this * Resources.getSystem().displayMetrics.density).toInt() |
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
Oops, something went wrong.