@craft-native/android 0.0.174 → 0.0.176
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/README.md +12 -2
- package/dist/index.d.ts +19 -0
- package/dist/index.js +20 -3
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
- package/templates/AndroidManifest.xml.template +1 -0
- package/templates/CraftBridge.kt.template +51 -0
- package/templates/CraftCrashReporter.kt.template +544 -0
- package/templates/CraftNative.kt.template +17 -0
- package/templates/CraftNativeFlatList.kt.template +20 -9
- package/templates/CraftNativeMutation.kt.template +4 -1
- package/templates/CraftNativeServices.kt.template +31 -1
- package/templates/MainActivityNative.kt.template +998 -303
- package/templates/build.gradle.kts.app.template +4 -2
|
@@ -49,8 +49,19 @@ internal class CraftNativeFlatList(context: Context) : RecyclerView(context) {
|
|
|
49
49
|
holder.host.layoutParams = holderLayoutParams()
|
|
50
50
|
val view = renderItem?.invoke(item.node, item.identity, holder.hostedView) ?: View(holder.host.context)
|
|
51
51
|
val renderedLayout = view.layoutParams
|
|
52
|
+
// iOS pins every row root to the collection cell's content width.
|
|
53
|
+
// A freshly-rendered Android root normally carries WRAP_CONTENT,
|
|
54
|
+
// which otherwise shrinks a vertical row to its text width and
|
|
55
|
+
// makes the two hosts disagree on hit/background geometry. Keep an
|
|
56
|
+
// authored width when one exists; only the default is promoted.
|
|
57
|
+
val renderedWidth = renderedLayout?.width ?: LayoutParams.WRAP_CONTENT
|
|
58
|
+
val hostedWidth = if (!horizontal && renderedWidth == LayoutParams.WRAP_CONTENT) {
|
|
59
|
+
LayoutParams.MATCH_PARENT
|
|
60
|
+
} else {
|
|
61
|
+
renderedWidth
|
|
62
|
+
}
|
|
52
63
|
val hostedLayout = FrameLayout.LayoutParams(
|
|
53
|
-
|
|
64
|
+
hostedWidth,
|
|
54
65
|
renderedLayout?.height ?: LayoutParams.WRAP_CONTENT,
|
|
55
66
|
)
|
|
56
67
|
if (renderedLayout is ViewGroup.MarginLayoutParams) {
|
|
@@ -202,14 +213,14 @@ internal class CraftNativeFlatList(context: Context) : RecyclerView(context) {
|
|
|
202
213
|
}
|
|
203
214
|
|
|
204
215
|
fun setContentContainerStyle(style: JSONObject?, density: Float) {
|
|
205
|
-
val padding = (style
|
|
206
|
-
val horizontal = (style
|
|
207
|
-
val vertical = (style
|
|
216
|
+
val padding = craftNativePadding(style, "padding", 0, density)
|
|
217
|
+
val horizontal = craftNativePadding(style, "paddingHorizontal", padding, density)
|
|
218
|
+
val vertical = craftNativePadding(style, "paddingVertical", padding, density)
|
|
208
219
|
setPadding(
|
|
209
|
-
(
|
|
210
|
-
(
|
|
211
|
-
(
|
|
212
|
-
(
|
|
220
|
+
craftNativePadding(style, "paddingLeft", horizontal, density),
|
|
221
|
+
craftNativePadding(style, "paddingTop", vertical, density),
|
|
222
|
+
craftNativePadding(style, "paddingRight", horizontal, density),
|
|
223
|
+
craftNativePadding(style, "paddingBottom", vertical, density),
|
|
213
224
|
)
|
|
214
225
|
clipToPadding = true
|
|
215
226
|
requestLayout()
|
|
@@ -228,7 +239,7 @@ internal class CraftNativeFlatList(context: Context) : RecyclerView(context) {
|
|
|
228
239
|
this.renderItem = renderItem
|
|
229
240
|
this.recycleItem = recycleItem
|
|
230
241
|
this.endReached = endReached
|
|
231
|
-
threshold = endReachedThreshold.coerceAtLeast(0.0)
|
|
242
|
+
threshold = endReachedThreshold.takeIf { it.isFinite() }?.coerceAtLeast(0.0) ?: 0.1
|
|
232
243
|
|
|
233
244
|
val nextColumns = columns.coerceAtLeast(1)
|
|
234
245
|
val layoutChanged = this.horizontal != horizontal || this.columns != nextColumns
|
|
@@ -151,6 +151,9 @@ class CraftNativeMutationDocument {
|
|
|
151
151
|
|
|
152
152
|
fun node(id: String): JSONObject? = materialize(id, nodes)
|
|
153
153
|
|
|
154
|
+
/** The committed parent used to redraw a child that has no native view. */
|
|
155
|
+
fun parentId(id: String): String? = nodes[id]?.parent
|
|
156
|
+
|
|
154
157
|
private fun createNode(
|
|
155
158
|
operation: JSONObject,
|
|
156
159
|
nodes: MutableMap<String, Node>,
|
|
@@ -271,7 +274,7 @@ class CraftNativeMutationDocument {
|
|
|
271
274
|
val CONTAINER_TYPES = setOf(
|
|
272
275
|
"View", "SafeAreaView", "ScrollView", "KeyboardAvoidingView", "Modal", "Pressable",
|
|
273
276
|
"TouchableOpacity", "TouchableHighlight", "ImageBackground", "FlatList", "SectionList",
|
|
274
|
-
"Fragment", "Svg", "G",
|
|
277
|
+
"Fragment", "Svg", "G", "Map",
|
|
275
278
|
)
|
|
276
279
|
}
|
|
277
280
|
|
|
@@ -84,11 +84,13 @@ internal class CraftNativeServices(
|
|
|
84
84
|
if (config.optBoolean("enableKeepAwake")) add("keepAwake")
|
|
85
85
|
if (config.optBoolean("enableGeolocation") || config.optBoolean("enableBackgroundLocation")) add("geolocation")
|
|
86
86
|
if (config.optJSONObject("backgroundRefresh")?.optBoolean("enabled") == true || config.optBoolean("enablePushNotifications")) add("background")
|
|
87
|
+
// craft.crashReporter: the app's crash and error reporter (bughq).
|
|
88
|
+
if (CraftCrashReporter.enabled) add("crashReporter")
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
fun handles(module: String): Boolean = module in setOf(
|
|
90
92
|
"Dialog", "Browser", "Linking", "Share", "Push", "Health", "KeepAwake", "Brightness", "StatusBar", "Speech", "Background",
|
|
91
|
-
"Location", "Media",
|
|
93
|
+
"Location", "Media", "CrashReporter",
|
|
92
94
|
)
|
|
93
95
|
|
|
94
96
|
fun perform(module: String, method: String, args: JSONArray, completion: (CraftNativeCapabilityResult) -> Unit) {
|
|
@@ -122,6 +124,7 @@ internal class CraftNativeServices(
|
|
|
122
124
|
onBackgroundComplete?.invoke(args.optBoolean(0, true), args.opt(1) as? String)
|
|
123
125
|
done(success(true))
|
|
124
126
|
}
|
|
127
|
+
"CrashReporter" -> crashReporter(method, args, done)
|
|
125
128
|
else -> done(failure("UNKNOWN_ACTION", "Unsupported native API"))
|
|
126
129
|
}
|
|
127
130
|
} catch (error: Exception) {
|
|
@@ -436,6 +439,33 @@ internal class CraftNativeServices(
|
|
|
436
439
|
}
|
|
437
440
|
}
|
|
438
441
|
|
|
442
|
+
// MARK: Crash reporting (CraftCrashReporter.kt)
|
|
443
|
+
|
|
444
|
+
private fun crashReporter(method: String, args: JSONArray, done: (CraftNativeCapabilityResult) -> Unit) {
|
|
445
|
+
if (!CraftCrashReporter.enabled && method != "context") return done(failure("CAPABILITY_DISABLED", "Crash reporting is not configured"))
|
|
446
|
+
when (method) {
|
|
447
|
+
"capture" -> {
|
|
448
|
+
val event = args.optJSONObject(0) ?: return done(failure("INVALID_ARGUMENT", "capture needs an event"))
|
|
449
|
+
done(success(CraftCrashReporter.capture(event)))
|
|
450
|
+
}
|
|
451
|
+
"setUser" -> {
|
|
452
|
+
CraftCrashReporter.setUser(if (args.isNull(0)) null else args.optString(0))
|
|
453
|
+
done(success(true))
|
|
454
|
+
}
|
|
455
|
+
"addBreadcrumb" -> {
|
|
456
|
+
val crumb = args.optJSONObject(0) ?: return done(failure("INVALID_ARGUMENT", "addBreadcrumb needs a breadcrumb"))
|
|
457
|
+
CraftCrashReporter.addBreadcrumb(crumb)
|
|
458
|
+
done(success(true))
|
|
459
|
+
}
|
|
460
|
+
"flush" -> {
|
|
461
|
+
CraftCrashReporter.requestFlush()
|
|
462
|
+
done(success(true))
|
|
463
|
+
}
|
|
464
|
+
"context" -> done(success(if (CraftCrashReporter.enabled) CraftCrashReporter.context() else JSONObject().put("enabled", false)))
|
|
465
|
+
else -> done(failure("UNKNOWN_ACTION", "Unsupported CrashReporter method"))
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
439
469
|
// MARK: Health Connect
|
|
440
470
|
|
|
441
471
|
fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?): Boolean =
|