@craft-native/android 0.0.467 → 0.0.475

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@craft-native/android",
3
- "version": "0.0.467",
3
+ "version": "0.0.475",
4
4
  "homepage": "https://github.com/craft-native/craft/tree/main/packages/android#readme",
5
5
  "repository": {
6
6
  "type": "git",
@@ -844,6 +844,9 @@ internal class CraftNativeChrome(
844
844
  private val tabBar = LinearLayout(context)
845
845
  private val tabRow = LinearLayout(context)
846
846
  private val accessory = FrameLayout(context)
847
+ private val companionRow = LinearLayout(context)
848
+ private val companionViews = mutableListOf<Pair<FrameLayout, JSONObject>>()
849
+ private var renderedCompanionSpecs = ""
847
850
  private val accessoryIcon = ImageView(context)
848
851
  private val accessoryBadge = TextView(context)
849
852
  private var accessorySpec: JSONObject? = null
@@ -868,7 +871,11 @@ internal class CraftNativeChrome(
868
871
  private var tabBarHiddenByScreen = false
869
872
  private var visiblePath: String? = null
870
873
  private val accessorySelected: Boolean
871
- get() = accessorySpec?.optString("path")?.let { path -> visiblePath == path || visiblePath?.startsWith(path + "/") == true } == true
874
+ get() = accessorySpec?.let { isAccessorySelected(it) } == true || companionViews.any { isAccessorySelected(it.second) }
875
+ private fun isAccessorySelected(item: JSONObject): Boolean {
876
+ val path = item.optString("path")
877
+ return visiblePath == path || visiblePath?.startsWith(path + "/") == true
878
+ }
872
879
  private var swipeTracking = false
873
880
  private var swipeIntercepted = false
874
881
  private var horizontalScrollDeferred = false
@@ -965,6 +972,9 @@ internal class CraftNativeChrome(
965
972
  tabRow.gravity = Gravity.CENTER_VERTICAL
966
973
  tabRow.setPadding(dp(12), dp(4), dp(12), dp(4))
967
974
  tabRow.addView(tabBar, LayoutParams(0, dp(64), 1f))
975
+ companionRow.orientation = HORIZONTAL
976
+ companionRow.gravity = Gravity.CENTER_VERTICAL
977
+ tabRow.addView(companionRow, LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, dp(64)))
968
978
  accessory.addView(accessoryIcon, FrameLayout.LayoutParams(dp(26), dp(26), Gravity.CENTER))
969
979
  accessoryBadge.textSize = 10f
970
980
  accessoryBadge.gravity = Gravity.CENTER
@@ -1087,6 +1097,24 @@ internal class CraftNativeChrome(
1087
1097
  path.startsWith("/") && !path.startsWith("//") && it.has("title")
1088
1098
  }
1089
1099
  accessory.visibility = if (accessorySpec == null) View.GONE else View.VISIBLE
1100
+ val companions = accessorySpec?.optJSONArray("companions")
1101
+ val companionSpecs = companions?.toString().orEmpty()
1102
+ if (companionSpecs != renderedCompanionSpecs) {
1103
+ renderedCompanionSpecs = companionSpecs
1104
+ companionRow.removeAllViews()
1105
+ companionViews.clear()
1106
+ for (index in 0 until minOf(companions?.length() ?: 0, 2)) {
1107
+ val item = companions?.optJSONObject(index) ?: continue
1108
+ val path = item.optString("path")
1109
+ if (!path.startsWith("/") || path.startsWith("//") || path == accessorySpec?.optString("path") || !item.has("title")) continue
1110
+ val action = FrameLayout(context)
1111
+ action.contentDescription = item.optString("accessibilityLabel").ifBlank { item.optString("title") }
1112
+ action.addView(ImageView(context), FrameLayout.LayoutParams(dp(26), dp(26), Gravity.CENTER))
1113
+ action.setOnClickListener { onAccessory?.invoke(path) }
1114
+ companionRow.addView(action, LayoutParams(dp(48), dp(48)).apply { marginStart = dp(8) })
1115
+ companionViews.add(action to item)
1116
+ }
1117
+ }
1090
1118
  accessorySpec?.let {
1091
1119
  accessory.contentDescription = it.optString("accessibilityLabel").ifBlank { it.optString("title") } + it.optString("badge").takeIf { badge -> badge.isNotBlank() && badge != "null" }?.let { badge -> ", $badge" }.orEmpty()
1092
1120
  accessoryBadge.text = it.optString("badge").takeUnless { badge -> badge == "null" }.orEmpty().take(8)
@@ -1191,9 +1219,16 @@ internal class CraftNativeChrome(
1191
1219
  backButton.imageTintList = ColorStateList.valueOf(accent)
1192
1220
  val surface = if (dark) Color.parseColor("#1C1C1E") else Color.parseColor("#F9F9F9")
1193
1221
  tabBar.background = GradientDrawable().apply { setColor(surface); cornerRadius = dp(32).toFloat() }
1194
- accessory.isSelected = accessorySelected
1195
- accessory.background = GradientDrawable().apply { setColor(if (accessorySelected) Color.argb(36, Color.red(accent), Color.green(accent), Color.blue(accent)) else surface); cornerRadius = dp(32).toFloat() }
1196
- accessorySpec?.let { accessoryIcon.setImageDrawable(CraftNativeIcons.drawable(context, null, it.optString("symbol"), if (accessorySelected) accent else text)) }
1222
+ val primarySelected = accessorySpec?.let { isAccessorySelected(it) } == true
1223
+ accessory.isSelected = primarySelected
1224
+ companionViews.forEach { (action, item) ->
1225
+ val selected = isAccessorySelected(item)
1226
+ action.isSelected = selected
1227
+ action.background = GradientDrawable().apply { setColor(if (selected) Color.argb(36, Color.red(accent), Color.green(accent), Color.blue(accent)) else surface); cornerRadius = dp(32).toFloat() }
1228
+ (action.getChildAt(0) as ImageView).setImageDrawable(CraftNativeIcons.drawable(context, null, item.optString("symbol"), if (selected) accent else text))
1229
+ }
1230
+ accessory.background = GradientDrawable().apply { setColor(if (primarySelected) Color.argb(36, Color.red(accent), Color.green(accent), Color.blue(accent)) else surface); cornerRadius = dp(32).toFloat() }
1231
+ accessorySpec?.let { accessoryIcon.setImageDrawable(CraftNativeIcons.drawable(context, null, it.optString("symbol"), if (primarySelected) accent else text)) }
1197
1232
  tabViews.forEachIndexed { index, (icon, label) ->
1198
1233
  tabBar.getChildAt(index).isSelected = index == selectedTab && !accessorySelected
1199
1234
  tabBar.getChildAt(index).background = tabCellBackground(index, dark)