t3-code-android-nightly/patches/expo-sharing@58.0.23.patch
2026-11-25 00:37:05 +00:00

193 lines
8.9 KiB
Diff

diff --git a/android/src/main/java/expo/modules/sharing/SharingRecords.kt b/android/src/main/java/expo/modules/sharing/SharingRecords.kt
index 1113a0adbb951081dea5214a711fe1dbb5a3e814..e89529a43258ae3bd6ec730c19453aed5e5efac4 100644
--- a/android/src/main/java/expo/modules/sharing/SharingRecords.kt
+++ b/android/src/main/java/expo/modules/sharing/SharingRecords.kt
@@ -51,7 +51,8 @@ enum class ContentType(val value: String) : Enumerable {
internal data class SharePayload(
@Field var value: String = "",
@Field var shareType: ShareType = ShareType.Text,
- @Field var mimeType: String = "text/plain"
+ @Field var mimeType: String = "text/plain",
+ @Field var originalName: String? = null
) : Record
@OptimizedRecord
diff --git a/android/src/main/java/expo/modules/sharing/dataParsers/SimpleShareIntentDataParser.kt b/android/src/main/java/expo/modules/sharing/dataParsers/SimpleShareIntentDataParser.kt
index 3381c5fd207ebb4cd8e0301aac59d307939ff162..88984c7237751e3a859aa425a3dfe55ec6f7897e 100644
--- a/android/src/main/java/expo/modules/sharing/dataParsers/SimpleShareIntentDataParser.kt
+++ b/android/src/main/java/expo/modules/sharing/dataParsers/SimpleShareIntentDataParser.kt
@@ -3,6 +3,7 @@ package expo.modules.sharing
import android.content.Context
import android.content.Intent
import android.net.Uri
+import android.provider.OpenableColumns
internal class SimpleShareIntentDataParser {
companion object {
@@ -17,25 +18,26 @@ internal class SimpleShareIntentDataParser {
}
private fun handleSendAction(context: Context, intent: Intent, type: String): List<SharePayload> {
- return if (type == "text/plain") {
- val text = intent.getStringExtra(Intent.EXTRA_TEXT) ?: return emptyList()
- val isUrl = android.util.Patterns.WEB_URL.matcher(text).matches()
-
- listOf(
+ val stream = intent.getParcelableExtraCompat<Uri>(Intent.EXTRA_STREAM)
+ val text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT)?.toString()
+ if (stream == null) {
+ if (!type.startsWith("text/") || text == null) return emptyList()
+ return listOf(
SharePayload().apply {
value = text
- shareType = if (isUrl) {
- ShareType.Url
- } else {
- ShareType.Text
- }
- mimeType = "text/plain"
+ shareType = if (android.util.Patterns.WEB_URL.matcher(text).matches()) ShareType.Url else ShareType.Text
+ mimeType = type
}
)
- } else {
- val uri = intent.getParcelableExtraCompat<Uri>(Intent.EXTRA_STREAM)
- listOfNotNull(uri?.let { createUriPayload(context, it, type) })
}
+ val filePayload = createUriPayload(context, stream, type)
+ if (text.isNullOrBlank()) return listOf(filePayload)
+ val textPayload = SharePayload().apply {
+ value = text
+ shareType = if (android.util.Patterns.WEB_URL.matcher(text).matches()) ShareType.Url else ShareType.Text
+ mimeType = "text/plain"
+ }
+ return listOf(textPayload, filePayload)
}
private fun handleSendMultipleAction(context: Context, intent: Intent, type: String): List<SharePayload> {
@@ -45,10 +47,25 @@ internal class SimpleShareIntentDataParser {
private fun createUriPayload(context: Context, uri: Uri, defaultType: String): SharePayload {
val specificType = context.contentResolver.getType(uri) ?: defaultType
+ // A blank DISPLAY_NAME must stay null: consumers treat originalName as
+ // the attachment name, and an empty name fails contract validation.
+ val displayName = runCatching {
+ context.contentResolver.query(
+ uri,
+ arrayOf(OpenableColumns.DISPLAY_NAME),
+ null,
+ null,
+ null
+ )?.use { cursor ->
+ val column = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)
+ if (column >= 0 && cursor.moveToFirst()) cursor.getString(column) else null
+ }
+ }.getOrNull()?.takeIf { it.isNotBlank() }
return SharePayload().apply {
value = uri.toString()
- shareType = ShareType.fromMimeType(specificType)
+ shareType = if (specificType.startsWith("text/")) ShareType.File else ShareType.fromMimeType(specificType)
mimeType = specificType
+ originalName = displayName
}
}
}
diff --git a/build/Sharing.types.d.ts b/build/Sharing.types.d.ts
index 213447a18257338804e5adc911d8e035d5c10f23..ec6495189c7b14c00501ba8676899392dbe004b0 100644
--- a/build/Sharing.types.d.ts
+++ b/build/Sharing.types.d.ts
@@ -100,6 +100,11 @@ export type SharePayload = {
* @default 'text/plain'
*/
mimeType?: string;
+ /**
+ * The display name of a shared file, when the source app provided one.
+ * Populated on Android from the content resolver's `DISPLAY_NAME`.
+ */
+ originalName?: string | null;
};
export type BaseResolvedSharePayload = SharePayload & {
/**
diff --git a/plugin/build/ios/xcode/addPbxGroup.js b/plugin/build/ios/xcode/addPbxGroup.js
index 0867938bdc6df7aeba560cb84dc9c9156c842d95..6ff5be15de702c79cc932def1af68e4c801db48e 100644
--- a/plugin/build/ios/xcode/addPbxGroup.js
+++ b/plugin/build/ios/xcode/addPbxGroup.js
@@ -29,9 +29,23 @@ function addPbxGroup(xcodeProject, targetName, shareExtensionFiles, platformProj
}).flat();
// Add generated files
targetFiles.push(`${targetName}.entitlements`);
- targetFiles.push(`Info.plist`);
const sharedFiles = Object.values(shareExtensionFiles.sharedFiles ?? []).flat().map((file)=>_path().default.join(sharedFilesPath, file)).map((file)=>_path().default.relative(_path().default.join(platformProjectRoot, targetName, 'shared'), file));
- const { uuid: mainGroupUuid } = xcodeProject.addPbxGroup(targetFiles, targetName, targetName);
+ const { uuid: mainGroupUuid, pbxGroup: mainGroup } = xcodeProject.addPbxGroup(targetFiles, targetName, targetName);
+ // Xcode 27.2 rejects file references shared between groups. Bypass
+ // addPbxGroup's path deduplication so the widget keeps its own Info.plist.
+ const infoPlistReference = xcodeProject.generateUuid();
+ const fileReferences = xcodeProject.pbxFileReferenceSection();
+ fileReferences[infoPlistReference] = {
+ isa: 'PBXFileReference',
+ lastKnownFileType: 'text.plist.xml',
+ path: 'Info.plist',
+ sourceTree: '"<group>"'
+ };
+ fileReferences[`${infoPlistReference}_comment`] = 'Info.plist';
+ mainGroup.children.push({
+ value: infoPlistReference,
+ comment: 'Info.plist'
+ });
const { uuid: sharedGroupUuid } = xcodeProject.addPbxGroup(sharedFiles, 'shared', 'shared');
if (mainGroupUuid && sharedGroupUuid) {
// @ts-expect-error: TODO(@kitten): This used to be untyped, and is failing now
diff --git a/plugin/src/ios/xcode/addPbxGroup.ts b/plugin/src/ios/xcode/addPbxGroup.ts
index 943c263c0cf58be595bfc9745c91827da81befec..3a99a1822beb25fea3835123b9a4ad7ac3b4f8d5 100644
--- a/plugin/src/ios/xcode/addPbxGroup.ts
+++ b/plugin/src/ios/xcode/addPbxGroup.ts
@@ -19,14 +19,29 @@ export function addPbxGroup(
// Add generated files
targetFiles.push(`${targetName}.entitlements`);
- targetFiles.push(`Info.plist`);
const sharedFiles = Object.values(shareExtensionFiles.sharedFiles ?? [])
.flat()
.map((file) => path.join(sharedFilesPath, file))
.map((file) => path.relative(path.join(platformProjectRoot, targetName, 'shared'), file));
- const { uuid: mainGroupUuid } = xcodeProject.addPbxGroup(targetFiles, targetName, targetName);
+ const { uuid: mainGroupUuid, pbxGroup: mainGroup } = xcodeProject.addPbxGroup(
+ targetFiles,
+ targetName,
+ targetName
+ );
+ // Xcode 27.2 rejects file references shared between groups. Bypass
+ // addPbxGroup's path deduplication so the widget keeps its own Info.plist.
+ const infoPlistReference = xcodeProject.generateUuid();
+ const fileReferences = xcodeProject.pbxFileReferenceSection();
+ fileReferences[infoPlistReference] = {
+ isa: 'PBXFileReference',
+ lastKnownFileType: 'text.plist.xml',
+ path: 'Info.plist',
+ sourceTree: '"<group>"',
+ };
+ fileReferences[`${infoPlistReference}_comment`] = 'Info.plist';
+ mainGroup.children.push({ value: infoPlistReference, comment: 'Info.plist' });
const { uuid: sharedGroupUuid } = xcodeProject.addPbxGroup(sharedFiles, 'shared', 'shared');
if (mainGroupUuid && sharedGroupUuid) {
diff --git a/src/Sharing.types.ts b/src/Sharing.types.ts
index 1393ffaf5857bc2972f6138a1909b5ce294e4a8f..6a346f7bc6ef22aef0946d2da705ea629dec431d 100644
--- a/src/Sharing.types.ts
+++ b/src/Sharing.types.ts
@@ -108,6 +108,12 @@ export type SharePayload = {
* @default 'text/plain'
*/
mimeType?: string;
+
+ /**
+ * The display name of a shared file, when the source app provided one.
+ * Populated on Android from the content resolver's `DISPLAY_NAME`.
+ */
+ originalName?: string | null;
};
export type BaseResolvedSharePayload = SharePayload & {