react-native-kookit 0.4.4 → 0.4.6
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withContentUriCopy.d.ts","sourceRoot":"","sources":["../src/withContentUriCopy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAGb,MAAM,sBAAsB,CAAC;AAE9B;;;;;;;;;;GAUG;AACH,QAAA,MAAM,kBAAkB,EAAE,YAKzB,CAAC;
|
|
1
|
+
{"version":3,"file":"withContentUriCopy.d.ts","sourceRoot":"","sources":["../src/withContentUriCopy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAGb,MAAM,sBAAsB,CAAC;AAE9B;;;;;;;;;;GAUG;AACH,QAAA,MAAM,kBAAkB,EAAE,YAKzB,CAAC;AAwTF,eAAe,kBAAkB,CAAC"}
|
|
@@ -36,8 +36,9 @@ function addContentUriCopyKotlin(contents) {
|
|
|
36
36
|
}
|
|
37
37
|
const imports = [
|
|
38
38
|
"import android.content.Intent",
|
|
39
|
+
"import android.database.Cursor",
|
|
39
40
|
"import android.net.Uri",
|
|
40
|
-
"import android.
|
|
41
|
+
"import android.provider.OpenableColumns",
|
|
41
42
|
"import android.util.Log",
|
|
42
43
|
"import java.io.File",
|
|
43
44
|
"import java.io.FileOutputStream",
|
|
@@ -62,14 +63,22 @@ function addContentUriCopyKotlin(contents) {
|
|
|
62
63
|
const methods = `
|
|
63
64
|
// content:// URI cold-start copy - Added by react-native-kookit
|
|
64
65
|
override fun onNewIntent(intent: Intent) {
|
|
65
|
-
|
|
66
|
+
// Call super first so other modules (e.g. expo-share-intent) can process
|
|
67
|
+
// the original intent before we potentially rewrite it.
|
|
66
68
|
super.onNewIntent(intent)
|
|
69
|
+
copyContentUriOnColdStart(intent)
|
|
67
70
|
}
|
|
68
71
|
|
|
69
72
|
/**
|
|
70
|
-
* If [intent] carries a content:// URI
|
|
71
|
-
* the
|
|
72
|
-
*
|
|
73
|
+
* If [intent] carries a content:// URI via ACTION_VIEW, copy the file to
|
|
74
|
+
* the app's cache directory synchronously and rewrite the intent so that
|
|
75
|
+
* downstream code receives a plain file:// URI instead.
|
|
76
|
+
*
|
|
77
|
+
* ACTION_SEND intents are intentionally left untouched so that other modules
|
|
78
|
+
* (e.g. expo-share-intent) can query the ContentResolver with the original
|
|
79
|
+
* content:// URI. Rewriting the URI before those modules run causes a
|
|
80
|
+
* NullPointerException in ContentResolver.query() because file:// URIs are
|
|
81
|
+
* not supported by the ContentProvider.
|
|
73
82
|
*
|
|
74
83
|
* This consumes the one-shot URI permission while it is still valid,
|
|
75
84
|
* preventing "permission denied" errors in the JS layer.
|
|
@@ -77,14 +86,10 @@ function addContentUriCopyKotlin(contents) {
|
|
|
77
86
|
private fun copyContentUriOnColdStart(intent: Intent) {
|
|
78
87
|
try {
|
|
79
88
|
val action = intent.action
|
|
89
|
+
// Only handle ACTION_VIEW here. ACTION_SEND is handled by
|
|
90
|
+
// expo-share-intent (or similar) which needs the original content:// URI.
|
|
80
91
|
val uri: Uri? = when (action) {
|
|
81
92
|
Intent.ACTION_VIEW -> intent.data
|
|
82
|
-
Intent.ACTION_SEND -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
83
|
-
intent.getParcelableExtra(Intent.EXTRA_STREAM, Uri::class.java)
|
|
84
|
-
} else {
|
|
85
|
-
@Suppress("DEPRECATION")
|
|
86
|
-
intent.getParcelableExtra(Intent.EXTRA_STREAM)
|
|
87
|
-
}
|
|
88
93
|
else -> null
|
|
89
94
|
}
|
|
90
95
|
|
|
@@ -93,9 +98,25 @@ function addContentUriCopyKotlin(contents) {
|
|
|
93
98
|
val tempDir = File(cacheDir, "temp")
|
|
94
99
|
if (!tempDir.exists()) tempDir.mkdirs()
|
|
95
100
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
101
|
+
// Query ContentResolver for the real display name (handles systems like
|
|
102
|
+
// vivo OriginOS where uri.lastPathSegment is a bare numeric ID with no extension)
|
|
103
|
+
var displayName: String? = null
|
|
104
|
+
try {
|
|
105
|
+
val cursor: Cursor? = contentResolver.query(
|
|
106
|
+
uri, arrayOf(OpenableColumns.DISPLAY_NAME), null, null, null
|
|
107
|
+
)
|
|
108
|
+
cursor?.use {
|
|
109
|
+
if (it.moveToFirst()) {
|
|
110
|
+
val idx = it.getColumnIndex(OpenableColumns.DISPLAY_NAME)
|
|
111
|
+
if (idx != -1) displayName = it.getString(idx)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
} catch (_: Exception) {}
|
|
115
|
+
|
|
116
|
+
val rawName = displayName
|
|
117
|
+
?: uri.lastPathSegment
|
|
118
|
+
?.substringAfterLast('/')
|
|
119
|
+
?.substringAfterLast('%')
|
|
99
120
|
?: "imported_file_\${System.currentTimeMillis()}"
|
|
100
121
|
|
|
101
122
|
val safeName = rawName.replace(Regex("[\\\\/:*?\\u0022<>|]"), "_")
|
|
@@ -117,9 +138,9 @@ function addContentUriCopyKotlin(contents) {
|
|
|
117
138
|
Log.i("MainActivity", "Copied content URI to: \${destFile.absolutePath}")
|
|
118
139
|
|
|
119
140
|
val fileUri = Uri.fromFile(destFile)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
141
|
+
// Only ACTION_VIEW is rewritten; ACTION_SEND is left for other modules.
|
|
142
|
+
if (action == Intent.ACTION_VIEW) {
|
|
143
|
+
intent.data = fileUri
|
|
123
144
|
}
|
|
124
145
|
} catch (e: Exception) {
|
|
125
146
|
Log.w("MainActivity", "Failed to copy content URI: \${e.message}")
|
|
@@ -142,8 +163,9 @@ function addContentUriCopyJava(contents) {
|
|
|
142
163
|
}
|
|
143
164
|
const imports = [
|
|
144
165
|
"import android.content.Intent;",
|
|
166
|
+
"import android.database.Cursor;",
|
|
145
167
|
"import android.net.Uri;",
|
|
146
|
-
"import android.
|
|
168
|
+
"import android.provider.OpenableColumns;",
|
|
147
169
|
"import android.util.Log;",
|
|
148
170
|
"import java.io.File;",
|
|
149
171
|
"import java.io.FileOutputStream;",
|
|
@@ -170,14 +192,22 @@ function addContentUriCopyJava(contents) {
|
|
|
170
192
|
// content:// URI cold-start copy - Added by react-native-kookit
|
|
171
193
|
@Override
|
|
172
194
|
public void onNewIntent(Intent intent) {
|
|
173
|
-
|
|
195
|
+
// Call super first so other modules (e.g. expo-share-intent) can process
|
|
196
|
+
// the original intent before we potentially rewrite it.
|
|
174
197
|
super.onNewIntent(intent);
|
|
198
|
+
copyContentUriOnColdStart(intent);
|
|
175
199
|
}
|
|
176
200
|
|
|
177
201
|
/**
|
|
178
|
-
* If intent carries a content:// URI
|
|
179
|
-
*
|
|
180
|
-
*
|
|
202
|
+
* If intent carries a content:// URI via ACTION_VIEW, copy the file to the
|
|
203
|
+
* app's cache directory synchronously and rewrite the intent so that
|
|
204
|
+
* downstream code receives a plain file:// URI instead.
|
|
205
|
+
*
|
|
206
|
+
* ACTION_SEND intents are intentionally left untouched so that other modules
|
|
207
|
+
* (e.g. expo-share-intent) can query the ContentResolver with the original
|
|
208
|
+
* content:// URI. Rewriting the URI before those modules run causes a
|
|
209
|
+
* NullPointerException in ContentResolver.query() because file:// URIs are
|
|
210
|
+
* not supported by the ContentProvider.
|
|
181
211
|
*
|
|
182
212
|
* This consumes the one-shot URI permission while it is still valid,
|
|
183
213
|
* preventing "permission denied" errors in the JS layer.
|
|
@@ -186,15 +216,11 @@ function addContentUriCopyJava(contents) {
|
|
|
186
216
|
if (intent == null) return;
|
|
187
217
|
try {
|
|
188
218
|
String action = intent.getAction();
|
|
219
|
+
// Only handle ACTION_VIEW here. ACTION_SEND is handled by
|
|
220
|
+
// expo-share-intent (or similar) which needs the original content:// URI.
|
|
189
221
|
Uri uri = null;
|
|
190
222
|
if (Intent.ACTION_VIEW.equals(action)) {
|
|
191
223
|
uri = intent.getData();
|
|
192
|
-
} else if (Intent.ACTION_SEND.equals(action)) {
|
|
193
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
194
|
-
uri = intent.getParcelableExtra(Intent.EXTRA_STREAM, Uri.class);
|
|
195
|
-
} else {
|
|
196
|
-
uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
|
197
|
-
}
|
|
198
224
|
}
|
|
199
225
|
|
|
200
226
|
if (uri == null || !"content".equals(uri.getScheme())) return;
|
|
@@ -202,11 +228,35 @@ function addContentUriCopyJava(contents) {
|
|
|
202
228
|
File tempDir = new File(getCacheDir(), "temp");
|
|
203
229
|
if (!tempDir.exists()) tempDir.mkdirs();
|
|
204
230
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
231
|
+
// Query ContentResolver for the real display name (handles systems like
|
|
232
|
+
// vivo OriginOS where uri.getLastPathSegment() is a bare numeric ID with no extension)
|
|
233
|
+
String displayName = null;
|
|
234
|
+
try {
|
|
235
|
+
Cursor cursor = getContentResolver().query(
|
|
236
|
+
uri, new String[]{OpenableColumns.DISPLAY_NAME}, null, null, null
|
|
237
|
+
);
|
|
238
|
+
if (cursor != null) {
|
|
239
|
+
try {
|
|
240
|
+
if (cursor.moveToFirst()) {
|
|
241
|
+
int idx = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
|
242
|
+
if (idx != -1) displayName = cursor.getString(idx);
|
|
243
|
+
}
|
|
244
|
+
} finally {
|
|
245
|
+
cursor.close();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
} catch (Exception ignored) {}
|
|
249
|
+
|
|
250
|
+
String rawName;
|
|
251
|
+
if (displayName != null && !displayName.isEmpty()) {
|
|
252
|
+
rawName = displayName;
|
|
253
|
+
} else {
|
|
254
|
+
String lastSegment = uri.getLastPathSegment();
|
|
255
|
+
rawName = (lastSegment != null && !lastSegment.isEmpty())
|
|
256
|
+
? lastSegment.substring(lastSegment.lastIndexOf('/') + 1)
|
|
257
|
+
: "imported_file_" + System.currentTimeMillis();
|
|
258
|
+
if (rawName.isEmpty()) rawName = "imported_file_" + System.currentTimeMillis();
|
|
259
|
+
}
|
|
210
260
|
String safeName = rawName.replaceAll("[\\\\/:\\*?\"<>|]", "_");
|
|
211
261
|
if (safeName.isEmpty()) safeName = "imported_file_" + System.currentTimeMillis();
|
|
212
262
|
|
|
@@ -231,10 +281,9 @@ function addContentUriCopyJava(contents) {
|
|
|
231
281
|
Log.i("MainActivity", "Copied content URI to: " + destFile.getAbsolutePath());
|
|
232
282
|
|
|
233
283
|
Uri fileUri = Uri.fromFile(destFile);
|
|
284
|
+
// Only ACTION_VIEW is rewritten; ACTION_SEND is left for other modules.
|
|
234
285
|
if (Intent.ACTION_VIEW.equals(action)) {
|
|
235
286
|
intent.setData(fileUri);
|
|
236
|
-
} else if (Intent.ACTION_SEND.equals(action)) {
|
|
237
|
-
intent.putExtra(Intent.EXTRA_STREAM, fileUri);
|
|
238
287
|
}
|
|
239
288
|
} catch (Exception e) {
|
|
240
289
|
Log.w("MainActivity", "Failed to copy content URI: " + e.getMessage());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withContentUriCopy.js","sourceRoot":"","sources":["../src/withContentUriCopy.ts"],"names":[],"mappings":";;AAAA,yDAI8B;AAE9B;;;;;;;;;;GAUG;AACH,MAAM,kBAAkB,GAAiB,CAAC,MAAM,EAAE,EAAE;IAClD,OAAO,IAAA,iCAAgB,EAAC,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;QACzC,MAAM,CAAC,UAAU,GAAG,+BAA+B,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACvE,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,SAAS,+BAA+B,CACtC,YAAwD;IAExD,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,YAAY,CAAC;IAE5C,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACtB,YAAY,CAAC,QAAQ,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