expo-widgets 58.0.1 → 58.0.2
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/.npmignore +5 -0
- package/CHANGELOG.md +6 -0
- package/android/build.gradle +2 -2
- package/android/src/main/java/expo/modules/widgets/ExpoWidgetEmittableTree.kt +95 -9
- package/android/src/main/java/expo/modules/widgets/ExpoWidgetsPeekWidget.kt +3 -1
- package/android/src/main/java/expo/modules/widgets/WidgetImageLoader.kt +159 -0
- package/bundle/index.ts +3 -3
- package/bundle/react-native-stub.ts +22 -2
- package/package.json +4 -4
package/.npmignore
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,12 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 58.0.2 — 2026-09-15
|
|
14
|
+
|
|
15
|
+
### 🎉 New features
|
|
16
|
+
|
|
17
|
+
- [Android] Add support for the `Image` component. ([#50116](https://github.com/expo/expo/pull/50116) by [@jakex7](https://github.com/jakex7))
|
|
18
|
+
|
|
13
19
|
## 58.0.1 — 2026-09-14
|
|
14
20
|
|
|
15
21
|
### 🎉 New features
|
package/android/build.gradle
CHANGED
|
@@ -6,7 +6,7 @@ plugins {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
group = 'expo.modules.widgets'
|
|
9
|
-
version = '58.0.
|
|
9
|
+
version = '58.0.2'
|
|
10
10
|
|
|
11
11
|
def expoWidgetsPackageDirFile = project.projectDir.parentFile
|
|
12
12
|
def expoWidgetsPackageDir = expoWidgetsPackageDirFile.absolutePath
|
|
@@ -39,7 +39,7 @@ android {
|
|
|
39
39
|
namespace "expo.modules.widgets"
|
|
40
40
|
defaultConfig {
|
|
41
41
|
versionCode 1
|
|
42
|
-
versionName '58.0.
|
|
42
|
+
versionName '58.0.2'
|
|
43
43
|
|
|
44
44
|
externalNativeBuild {
|
|
45
45
|
cmake {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
@file:SuppressLint("RestrictedApi")
|
|
2
|
+
|
|
1
3
|
package expo.modules.widgets
|
|
2
4
|
|
|
5
|
+
import android.annotation.SuppressLint
|
|
3
6
|
import android.content.Context
|
|
4
7
|
import android.graphics.Color as AndroidColor
|
|
8
|
+
import androidx.compose.ui.unit.DpSize
|
|
5
9
|
import androidx.compose.ui.unit.TextUnit
|
|
6
10
|
import androidx.compose.ui.unit.dp
|
|
7
11
|
import androidx.compose.ui.unit.sp
|
|
@@ -22,6 +26,8 @@ import expo.modules.ui.FillMaxHeightParams
|
|
|
22
26
|
import expo.modules.ui.FillMaxSizeParams
|
|
23
27
|
import expo.modules.ui.FillMaxWidthParams
|
|
24
28
|
import expo.modules.ui.HeightParams
|
|
29
|
+
import expo.modules.ui.graphics.ImageSource
|
|
30
|
+
import expo.modules.ui.image.ImageContentScale
|
|
25
31
|
import expo.modules.ui.LayoutProps
|
|
26
32
|
import expo.modules.ui.LinearProgressIndicatorProps
|
|
27
33
|
import expo.modules.ui.LoadingIndicatorProps
|
|
@@ -54,6 +60,9 @@ import expo.modules.ui.convertibles.VerticalArrangementDefault
|
|
|
54
60
|
import androidx.compose.ui.graphics.Color
|
|
55
61
|
import androidx.glance.Emittable
|
|
56
62
|
import androidx.glance.EmittableButton
|
|
63
|
+
import androidx.glance.EmittableImage
|
|
64
|
+
import androidx.glance.ImageProvider
|
|
65
|
+
import androidx.glance.TintColorFilterParams
|
|
57
66
|
import androidx.glance.GlanceModifier
|
|
58
67
|
import androidx.glance.action.clickable
|
|
59
68
|
import androidx.glance.appwidget.CheckboxDefaults
|
|
@@ -67,6 +76,7 @@ import androidx.glance.appwidget.RadioButtonDefaults
|
|
|
67
76
|
import androidx.glance.appwidget.SwitchDefaults
|
|
68
77
|
import androidx.glance.background
|
|
69
78
|
import androidx.glance.layout.Alignment
|
|
79
|
+
import androidx.glance.layout.ContentScale
|
|
70
80
|
import androidx.glance.layout.EmittableBox
|
|
71
81
|
import androidx.glance.layout.EmittableColumn
|
|
72
82
|
import androidx.glance.layout.EmittableRow
|
|
@@ -80,6 +90,8 @@ import androidx.glance.layout.size
|
|
|
80
90
|
import androidx.glance.layout.width
|
|
81
91
|
import androidx.glance.layout.wrapContentHeight
|
|
82
92
|
import androidx.glance.layout.wrapContentWidth
|
|
93
|
+
import androidx.glance.semantics.contentDescription
|
|
94
|
+
import androidx.glance.semantics.semantics
|
|
83
95
|
import androidx.glance.text.EmittableText
|
|
84
96
|
import androidx.glance.text.FontStyle
|
|
85
97
|
import androidx.glance.text.FontWeight
|
|
@@ -92,6 +104,7 @@ import androidx.glance.appwidget.lazy.EmittableLazyColumn
|
|
|
92
104
|
import androidx.glance.appwidget.lazy.EmittableLazyListItem
|
|
93
105
|
import androidx.glance.appwidget.lazy.ReservedItemIdRangeEnd
|
|
94
106
|
import io.github.jakex7.peek.glance.determinateCircularProgressIndicatorEmittable
|
|
107
|
+
import kotlin.math.roundToInt
|
|
95
108
|
|
|
96
109
|
private val DefaultCheckedColor = ColorProvider(Color(0xff6750a4))
|
|
97
110
|
private val DefaultUncheckedColor = ColorProvider(Color(0xff79747e))
|
|
@@ -99,13 +112,14 @@ private val DefaultCheckedTrackColor = ColorProvider(Color(0xffe8def8))
|
|
|
99
112
|
private val DefaultUncheckedTrackColor = ColorProvider(Color(0xffe7e0ec))
|
|
100
113
|
|
|
101
114
|
private class WidgetConverterContext(
|
|
102
|
-
override val applicationContext: Context
|
|
115
|
+
override val applicationContext: Context,
|
|
116
|
+
val widgetSize: DpSize
|
|
103
117
|
) : ConverterContext {
|
|
104
118
|
override val runtime: Runtime? = null
|
|
105
119
|
}
|
|
106
120
|
|
|
107
|
-
internal fun ReadableMap.toPeekRoot(context: Context, source: String): Emittable {
|
|
108
|
-
val converterContext = WidgetConverterContext(context)
|
|
121
|
+
internal fun ReadableMap.toPeekRoot(context: Context, source: String, size: DpSize): Emittable {
|
|
122
|
+
val converterContext = WidgetConverterContext(context, size)
|
|
109
123
|
return EmittableColumn().also { root ->
|
|
110
124
|
root.children += toPeekNodes(converterContext, source)
|
|
111
125
|
}
|
|
@@ -120,12 +134,13 @@ private fun createErrorText(message: String): EmittableText {
|
|
|
120
134
|
}
|
|
121
135
|
}
|
|
122
136
|
|
|
123
|
-
private fun ReadableMap.toPeekNodes(converterContext:
|
|
137
|
+
private fun ReadableMap.toPeekNodes(converterContext: WidgetConverterContext, source: String): List<Emittable> {
|
|
124
138
|
return when (typeName()) {
|
|
125
139
|
"BoxView" -> listOf(toPeekBox(converterContext, source))
|
|
126
140
|
"CheckboxView" -> listOf(toPeekCheckBox(converterContext))
|
|
127
141
|
"CircularProgressIndicatorView" -> listOf(toPeekCircularProgress(converterContext))
|
|
128
142
|
"ColumnView" -> listOf(toPeekColumn(converterContext, source))
|
|
143
|
+
"ImageView" -> listOf(toPeekImage(converterContext))
|
|
129
144
|
"LazyColumnView" -> listOf(toPeekLazyColumn(converterContext, source))
|
|
130
145
|
"LinearProgressIndicatorView" -> listOf(toPeekLinearProgress(converterContext))
|
|
131
146
|
"LoadingIndicatorView" -> listOf(toPeekLoadingIndicator(converterContext))
|
|
@@ -143,7 +158,7 @@ private fun ReadableMap.toPeekNodes(converterContext: ConverterContext, source:
|
|
|
143
158
|
}
|
|
144
159
|
}
|
|
145
160
|
|
|
146
|
-
private fun ReadableMap.toPeekBox(converterContext:
|
|
161
|
+
private fun ReadableMap.toPeekBox(converterContext: WidgetConverterContext, source: String): EmittableBox {
|
|
147
162
|
val props = props<LayoutProps>(converterContext)
|
|
148
163
|
return EmittableBox().also {
|
|
149
164
|
it.modifier = props.modifiers.toPeekModifier(converterContext)
|
|
@@ -152,7 +167,7 @@ private fun ReadableMap.toPeekBox(converterContext: ConverterContext, source: St
|
|
|
152
167
|
}
|
|
153
168
|
}
|
|
154
169
|
|
|
155
|
-
private fun ReadableMap.toPeekRow(converterContext:
|
|
170
|
+
private fun ReadableMap.toPeekRow(converterContext: WidgetConverterContext, source: String): EmittableRow {
|
|
156
171
|
val props = props<LayoutProps>(converterContext)
|
|
157
172
|
return EmittableRow().also {
|
|
158
173
|
it.modifier = props.modifiers.toPeekModifier(converterContext)
|
|
@@ -162,7 +177,7 @@ private fun ReadableMap.toPeekRow(converterContext: ConverterContext, source: St
|
|
|
162
177
|
}
|
|
163
178
|
}
|
|
164
179
|
|
|
165
|
-
private fun ReadableMap.toPeekColumn(converterContext:
|
|
180
|
+
private fun ReadableMap.toPeekColumn(converterContext: WidgetConverterContext, source: String): EmittableColumn {
|
|
166
181
|
val props = props<LayoutProps>(converterContext)
|
|
167
182
|
return EmittableColumn().also {
|
|
168
183
|
it.modifier = props.modifiers.toPeekModifier(converterContext)
|
|
@@ -172,7 +187,7 @@ private fun ReadableMap.toPeekColumn(converterContext: ConverterContext, source:
|
|
|
172
187
|
}
|
|
173
188
|
}
|
|
174
189
|
|
|
175
|
-
private fun ReadableMap.toPeekLazyColumn(converterContext:
|
|
190
|
+
private fun ReadableMap.toPeekLazyColumn(converterContext: WidgetConverterContext, source: String): EmittableLazyColumn {
|
|
176
191
|
val props = props<LayoutProps>(converterContext)
|
|
177
192
|
val alignment = props.toPeekHorizontalAlignment()
|
|
178
193
|
return EmittableLazyColumn().also { lazyColumn ->
|
|
@@ -214,7 +229,68 @@ private fun ReadableMap.toPeekText(converterContext: ConverterContext): Emittabl
|
|
|
214
229
|
}
|
|
215
230
|
}
|
|
216
231
|
|
|
217
|
-
private fun ReadableMap.
|
|
232
|
+
private fun ReadableMap.toPeekImage(converterContext: WidgetConverterContext): Emittable {
|
|
233
|
+
val props = props<WidgetImageProps>(converterContext)
|
|
234
|
+
val source = props.source
|
|
235
|
+
?: return createErrorText("Image has no source. Pass source={{ uri }} with a drawable resource name or a file URI.")
|
|
236
|
+
val provider = runCatching {
|
|
237
|
+
loadWidgetImage(converterContext.applicationContext, source, props.imageTarget(converterContext))
|
|
238
|
+
}.getOrElse { error ->
|
|
239
|
+
return createErrorText(error.message ?: "Image '${source.uri}' could not be loaded.")
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return EmittableImage().also {
|
|
243
|
+
it.provider = provider
|
|
244
|
+
it.modifier = props.imageModifier(converterContext)
|
|
245
|
+
it.contentScale = props.contentScale.toGlanceContentScale()
|
|
246
|
+
it.colorFilterParams = props.tint.toGlanceColorProvider()?.let(::TintColorFilterParams)
|
|
247
|
+
it.alpha = props.alpha.coerceIn(0f, 1f)
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
private fun WidgetImageProps.imageModifier(converterContext: ConverterContext): GlanceModifier {
|
|
252
|
+
val modifier = modifiers.toPeekModifier(converterContext)
|
|
253
|
+
val description = contentDescription ?: return modifier
|
|
254
|
+
return modifier.semantics { contentDescription = description }
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
private fun WidgetImageProps.imageTarget(converterContext: WidgetConverterContext): WidgetImageTarget {
|
|
258
|
+
val metrics = converterContext.applicationContext.resources.displayMetrics
|
|
259
|
+
var widthDp = converterContext.widgetSize.width.value.takeIf { it.isFinite() && it > 0f }
|
|
260
|
+
?: (metrics.widthPixels / metrics.density)
|
|
261
|
+
var heightDp = converterContext.widgetSize.height.value.takeIf { it.isFinite() && it > 0f }
|
|
262
|
+
?: (metrics.heightPixels / metrics.density)
|
|
263
|
+
|
|
264
|
+
for (modifier in modifiers) {
|
|
265
|
+
when (modifier["\$type"]?.asString()) {
|
|
266
|
+
"size" -> modifier.asRecord<SizeParams>(converterContext)?.let {
|
|
267
|
+
widthDp = it.width.toFloat()
|
|
268
|
+
heightDp = it.height.toFloat()
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
"width" -> modifier.asRecord<WidthParams>(converterContext)?.let { widthDp = it.width.toFloat() }
|
|
272
|
+
"height" -> modifier.asRecord<HeightParams>(converterContext)?.let { heightDp = it.height.toFloat() }
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return WidgetImageTarget(
|
|
277
|
+
widthPx = (widthDp * metrics.density).roundToInt().coerceAtLeast(1),
|
|
278
|
+
heightPx = (heightDp * metrics.density).roundToInt().coerceAtLeast(1)
|
|
279
|
+
)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
private fun ImageContentScale.toGlanceContentScale(): ContentScale {
|
|
283
|
+
return when (this) {
|
|
284
|
+
ImageContentScale.FIT -> ContentScale.Fit
|
|
285
|
+
ImageContentScale.CROP -> ContentScale.Crop
|
|
286
|
+
ImageContentScale.FILL_BOUNDS -> ContentScale.FillBounds
|
|
287
|
+
// RemoteViews only offers fit, crop and stretch, so the remaining scales map to the nearest one.
|
|
288
|
+
ImageContentScale.INSIDE, ImageContentScale.NONE -> ContentScale.Fit
|
|
289
|
+
ImageContentScale.FILL_WIDTH, ImageContentScale.FILL_HEIGHT -> ContentScale.Crop
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
private fun ReadableMap.toPeekButton(converterContext: WidgetConverterContext, source: String): Emittable {
|
|
218
294
|
val props = props<WidgetButtonProps>(converterContext)
|
|
219
295
|
val children = children()
|
|
220
296
|
val action =
|
|
@@ -603,3 +679,13 @@ internal data class WidgetButtonProps(
|
|
|
603
679
|
val modifiers: ModifierList = emptyList(),
|
|
604
680
|
val target: String? = null
|
|
605
681
|
) : ComposeProps
|
|
682
|
+
|
|
683
|
+
@OptimizedComposeProps
|
|
684
|
+
internal data class WidgetImageProps(
|
|
685
|
+
val source: ImageSource? = null,
|
|
686
|
+
val contentScale: ImageContentScale = ImageContentScale.FIT,
|
|
687
|
+
val contentDescription: String? = null,
|
|
688
|
+
val tint: AndroidColor? = null,
|
|
689
|
+
val alpha: Float = 1f,
|
|
690
|
+
val modifiers: ModifierList = emptyList()
|
|
691
|
+
) : ComposeProps
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
@file:SuppressLint("RestrictedApi")
|
|
1
2
|
package expo.modules.widgets
|
|
2
3
|
|
|
4
|
+
import android.annotation.SuppressLint
|
|
3
5
|
import android.content.Context
|
|
4
6
|
import android.os.Bundle
|
|
5
7
|
import androidx.compose.ui.unit.DpSize
|
|
@@ -26,6 +28,6 @@ internal class ExpoWidgetsPeekWidget(
|
|
|
26
28
|
val environment = getWidgetEnvironment(appContext)
|
|
27
29
|
val node = evaluateLayout(appContext, layout, props, environment)
|
|
28
30
|
|
|
29
|
-
return node.toPeekRoot(appContext, widgetName)
|
|
31
|
+
return node.toPeekRoot(appContext, widgetName, size)
|
|
30
32
|
}
|
|
31
33
|
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
@file:SuppressLint("RestrictedApi")
|
|
2
|
+
|
|
3
|
+
package expo.modules.widgets
|
|
4
|
+
|
|
5
|
+
import android.annotation.SuppressLint
|
|
6
|
+
import android.content.Context
|
|
7
|
+
import android.graphics.Bitmap
|
|
8
|
+
import android.graphics.BitmapFactory
|
|
9
|
+
import android.graphics.ImageDecoder
|
|
10
|
+
import android.graphics.Matrix
|
|
11
|
+
import android.media.ExifInterface
|
|
12
|
+
import android.net.Uri
|
|
13
|
+
import android.os.Build
|
|
14
|
+
import androidx.glance.ImageProvider
|
|
15
|
+
import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper
|
|
16
|
+
import expo.modules.ui.graphics.ImageSource
|
|
17
|
+
import java.io.FileNotFoundException
|
|
18
|
+
import java.io.InputStream
|
|
19
|
+
import kotlin.math.max
|
|
20
|
+
|
|
21
|
+
internal data class WidgetImageTarget(val widthPx: Int, val heightPx: Int)
|
|
22
|
+
|
|
23
|
+
// RemoteViews rejects a widget update whose bitmaps exceed its memory budget.
|
|
24
|
+
private const val MAX_WIDGET_IMAGE_PIXELS = 1_048_576L
|
|
25
|
+
private const val MAX_WIDGET_IMAGE_DIMENSION_PX = 2048
|
|
26
|
+
|
|
27
|
+
internal fun loadWidgetImage(context: Context, source: ImageSource, target: WidgetImageTarget): ImageProvider {
|
|
28
|
+
val uri = Uri.parse(source.uri)
|
|
29
|
+
return when (uri.scheme) {
|
|
30
|
+
null -> ImageProvider(resolveDrawableId(context, source.uri))
|
|
31
|
+
"file", "content", "android.resource" -> ImageProvider(decodeBitmap(context, uri, target))
|
|
32
|
+
"http", "https" -> throw IllegalArgumentException(
|
|
33
|
+
"Remote images are not supported in widgets ('${source.uri}'). Download the image to widgetsDirectory from the app and pass its file URI."
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
else -> throw IllegalArgumentException(
|
|
37
|
+
"Image URI scheme '${uri.scheme}' is not supported in widgets ('${source.uri}'). Pass a drawable resource name or a file URI."
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private fun resolveDrawableId(context: Context, name: String): Int {
|
|
43
|
+
val resourceId = ResourceDrawableIdHelper.getResourceDrawableId(context, name)
|
|
44
|
+
require(resourceId > 0) {
|
|
45
|
+
"Image resource '$name' was not found in the app's drawables. Add it to the app's res/drawable directory or pass a file URI."
|
|
46
|
+
}
|
|
47
|
+
return resourceId
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private fun decodeBitmap(context: Context, uri: Uri, target: WidgetImageTarget): Bitmap {
|
|
51
|
+
return runCatching {
|
|
52
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
53
|
+
ImageDecoder.decodeBitmap(ImageDecoder.createSource(context.contentResolver, uri)) { decoder, info, _ ->
|
|
54
|
+
decoder.allocator = ImageDecoder.ALLOCATOR_SOFTWARE
|
|
55
|
+
decoder.setTargetSampleSize(calculateInSampleSize(info.size.width, info.size.height, target))
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
decodeWithBitmapFactory(context, uri, target)
|
|
59
|
+
}
|
|
60
|
+
}.getOrElse { error ->
|
|
61
|
+
throw IllegalArgumentException(
|
|
62
|
+
if (error is FileNotFoundException) {
|
|
63
|
+
"Image '$uri' does not exist. Copy the image to widgetsDirectory before updating the widget."
|
|
64
|
+
} else {
|
|
65
|
+
"Image '$uri' could not be decoded. Widgets support bitmap formats such as PNG, JPEG and WebP."
|
|
66
|
+
},
|
|
67
|
+
error
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private fun decodeWithBitmapFactory(context: Context, uri: Uri, target: WidgetImageTarget): Bitmap {
|
|
73
|
+
val open: () -> InputStream = {
|
|
74
|
+
context.contentResolver.openInputStream(uri) ?: throw FileNotFoundException(uri.toString())
|
|
75
|
+
}
|
|
76
|
+
val orientation = open().use { input ->
|
|
77
|
+
runCatching {
|
|
78
|
+
ExifInterface(input).getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)
|
|
79
|
+
}.getOrDefault(ExifInterface.ORIENTATION_NORMAL)
|
|
80
|
+
}
|
|
81
|
+
val bounds = BitmapFactory.Options().apply { inJustDecodeBounds = true }
|
|
82
|
+
open().use { input -> BitmapFactory.decodeStream(input, null, bounds) }
|
|
83
|
+
require(bounds.outWidth > 0 && bounds.outHeight > 0) { "Image '$uri' has no decodable bounds." }
|
|
84
|
+
|
|
85
|
+
val swapsDimensions = orientation.swapsDimensions()
|
|
86
|
+
val options = BitmapFactory.Options().apply {
|
|
87
|
+
inSampleSize = calculateInSampleSize(
|
|
88
|
+
sourceWidth = if (swapsDimensions) {
|
|
89
|
+
bounds.outHeight
|
|
90
|
+
} else {
|
|
91
|
+
bounds.outWidth
|
|
92
|
+
},
|
|
93
|
+
sourceHeight = if (swapsDimensions) {
|
|
94
|
+
bounds.outWidth
|
|
95
|
+
} else {
|
|
96
|
+
bounds.outHeight
|
|
97
|
+
},
|
|
98
|
+
target = target
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
val bitmap = requireNotNull(open().use { input -> BitmapFactory.decodeStream(input, null, options) }) {
|
|
102
|
+
"Image '$uri' could not be decoded."
|
|
103
|
+
}
|
|
104
|
+
return bitmap.applyExifOrientation(orientation)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private fun calculateInSampleSize(sourceWidth: Int, sourceHeight: Int, target: WidgetImageTarget): Int {
|
|
108
|
+
val targetWidth = target.widthPx.coerceAtLeast(1)
|
|
109
|
+
val targetHeight = target.heightPx.coerceAtLeast(1)
|
|
110
|
+
var sampleSize = 1
|
|
111
|
+
while (sourceWidth / (sampleSize * 2) >= targetWidth && sourceHeight / (sampleSize * 2) >= targetHeight) {
|
|
112
|
+
sampleSize *= 2
|
|
113
|
+
}
|
|
114
|
+
while (
|
|
115
|
+
(sourceWidth.toLong() / sampleSize) * (sourceHeight.toLong() / sampleSize) > MAX_WIDGET_IMAGE_PIXELS ||
|
|
116
|
+
max(sourceWidth, sourceHeight) / sampleSize > MAX_WIDGET_IMAGE_DIMENSION_PX
|
|
117
|
+
) {
|
|
118
|
+
sampleSize *= 2
|
|
119
|
+
}
|
|
120
|
+
return sampleSize
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private fun Bitmap.applyExifOrientation(orientation: Int): Bitmap {
|
|
124
|
+
val matrix = Matrix()
|
|
125
|
+
when (orientation) {
|
|
126
|
+
ExifInterface.ORIENTATION_FLIP_HORIZONTAL -> matrix.setScale(-1f, 1f)
|
|
127
|
+
ExifInterface.ORIENTATION_ROTATE_180 -> matrix.setRotate(180f)
|
|
128
|
+
ExifInterface.ORIENTATION_FLIP_VERTICAL -> {
|
|
129
|
+
matrix.setRotate(180f)
|
|
130
|
+
matrix.postScale(-1f, 1f)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
ExifInterface.ORIENTATION_TRANSPOSE -> {
|
|
134
|
+
matrix.setRotate(90f)
|
|
135
|
+
matrix.postScale(-1f, 1f)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
ExifInterface.ORIENTATION_ROTATE_90 -> matrix.setRotate(90f)
|
|
139
|
+
ExifInterface.ORIENTATION_TRANSVERSE -> {
|
|
140
|
+
matrix.setRotate(-90f)
|
|
141
|
+
matrix.postScale(-1f, 1f)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
ExifInterface.ORIENTATION_ROTATE_270 -> matrix.setRotate(-90f)
|
|
145
|
+
else -> return this
|
|
146
|
+
}
|
|
147
|
+
return Bitmap.createBitmap(this, 0, 0, width, height, matrix, true).also { oriented ->
|
|
148
|
+
if (oriented !== this) {
|
|
149
|
+
recycle()
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private fun Int.swapsDimensions(): Boolean {
|
|
155
|
+
return this == ExifInterface.ORIENTATION_TRANSPOSE ||
|
|
156
|
+
this == ExifInterface.ORIENTATION_ROTATE_90 ||
|
|
157
|
+
this == ExifInterface.ORIENTATION_TRANSVERSE ||
|
|
158
|
+
this == ExifInterface.ORIENTATION_ROTATE_270
|
|
159
|
+
}
|
package/bundle/index.ts
CHANGED
|
@@ -102,10 +102,10 @@ const __expoWidgetHandlePress = function (
|
|
|
102
102
|
};
|
|
103
103
|
|
|
104
104
|
Object.assign(globalThis, {
|
|
105
|
-
...uiGlobals,
|
|
106
|
-
...jsxRuntime,
|
|
107
|
-
...React,
|
|
108
105
|
...ReactNative,
|
|
106
|
+
...React,
|
|
107
|
+
...jsxRuntime,
|
|
108
|
+
...uiGlobals,
|
|
109
109
|
React,
|
|
110
110
|
__expoWidgetRender,
|
|
111
111
|
__expoWidgetHandlePress,
|
|
@@ -2,10 +2,30 @@ export const PlatformColor = (...names: string[]) => {
|
|
|
2
2
|
return { semantic: names };
|
|
3
3
|
};
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
type ResolvedImageSource = {
|
|
6
|
+
uri: string;
|
|
7
|
+
width?: number;
|
|
8
|
+
height?: number;
|
|
9
|
+
scale?: number;
|
|
7
10
|
};
|
|
8
11
|
|
|
12
|
+
function resolveAssetSource(source: unknown): ResolvedImageSource | null {
|
|
13
|
+
if (source == null) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
if (typeof source === 'object' && typeof (source as ResolvedImageSource).uri === 'string') {
|
|
17
|
+
return source as ResolvedImageSource;
|
|
18
|
+
}
|
|
19
|
+
if (typeof source === 'number') {
|
|
20
|
+
throw new Error(
|
|
21
|
+
'Bundled require() image sources are not supported inside widgets. Copy the image to widgetsDirectory and pass source={{ uri }} instead.'
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
throw new Error('Widget Image source must be an object containing a uri string.');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const Image = { resolveAssetSource };
|
|
28
|
+
|
|
9
29
|
export const useColorScheme = (): 'light' | 'dark' | null => {
|
|
10
30
|
return (globalThis.__expoWidgetEnvironment?.colorScheme as 'light' | 'dark' | undefined) ?? null;
|
|
11
31
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-widgets",
|
|
3
|
-
"version": "58.0.
|
|
3
|
+
"version": "58.0.2",
|
|
4
4
|
"description": "Widgets.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"expo",
|
|
@@ -28,14 +28,14 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@expo/plist": "^0.9.0",
|
|
31
|
-
"@expo/ui": "~58.0.
|
|
31
|
+
"@expo/ui": "~58.0.2"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@expo/spawn-async": "^1.8.0",
|
|
35
35
|
"@types/jest": "^29.2.1",
|
|
36
36
|
"@types/node": "^22.14.0",
|
|
37
37
|
"@types/react": "~19.2.0",
|
|
38
|
-
"expo": "58.0.0-preview.
|
|
38
|
+
"expo": "58.0.0-preview.2",
|
|
39
39
|
"expo-module-scripts": "56.0.3",
|
|
40
40
|
"react-native": "0.88.0-rc.0",
|
|
41
41
|
"resolve-workspace-root": "^2.0.0"
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"react": "*",
|
|
46
46
|
"react-native": "*"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "313e67f5c9dfb16f9deca74a271cd1d4f33a6f82",
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "pnpm run build:lib && pnpm run build:plugin",
|
|
51
51
|
"build:lib": "expo-build src",
|