@onekeyfe/react-native-text-input 3.0.157-alpha.253 → 3.0.157-alpha.254
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/android/build.gradle
CHANGED
|
@@ -100,6 +100,10 @@ android {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
+
|
|
104
|
+
testOptions {
|
|
105
|
+
unitTests.includeAndroidResources = true
|
|
106
|
+
}
|
|
103
107
|
}
|
|
104
108
|
|
|
105
109
|
repositories {
|
|
@@ -115,6 +119,8 @@ dependencies {
|
|
|
115
119
|
//noinspection GradleDynamicVersion
|
|
116
120
|
implementation "com.facebook.react:react-android"
|
|
117
121
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
122
|
+
testImplementation "junit:junit:4.13.2"
|
|
123
|
+
testImplementation "org.robolectric:robolectric:4.17"
|
|
118
124
|
}
|
|
119
125
|
|
|
120
126
|
if (isNewArchitectureEnabled()) {
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
package com.textinput
|
|
2
|
+
|
|
3
|
+
import android.R
|
|
4
|
+
import android.content.ClipData
|
|
5
|
+
import android.content.ClipDescription
|
|
6
|
+
import android.content.ClipboardManager
|
|
7
|
+
import android.content.ContentProvider
|
|
8
|
+
import android.content.ContentValues
|
|
9
|
+
import android.content.Context
|
|
10
|
+
import android.database.Cursor
|
|
11
|
+
import android.net.Uri
|
|
12
|
+
import com.facebook.react.bridge.BridgeReactContext
|
|
13
|
+
import com.facebook.react.bridge.NativeModule
|
|
14
|
+
import com.facebook.react.uimanager.DisplayMetricsHolder
|
|
15
|
+
import org.junit.Assert.assertEquals
|
|
16
|
+
import org.junit.Assert.assertTrue
|
|
17
|
+
import org.junit.Test
|
|
18
|
+
import org.junit.runner.RunWith
|
|
19
|
+
import org.robolectric.RobolectricTestRunner
|
|
20
|
+
import org.robolectric.RuntimeEnvironment
|
|
21
|
+
import org.robolectric.annotation.Config
|
|
22
|
+
import org.robolectric.shadows.ShadowContentResolver
|
|
23
|
+
import so.onekey.app.wallet.pasteinput.PasteWatcher
|
|
24
|
+
|
|
25
|
+
@RunWith(RobolectricTestRunner::class)
|
|
26
|
+
@Config(sdk = [34])
|
|
27
|
+
class TextInputViewPasteTest {
|
|
28
|
+
@Test
|
|
29
|
+
fun textPasteReportsAndRunsNativePasteForBothMenuActions() {
|
|
30
|
+
for (action in listOf(R.id.paste, R.id.pasteAsPlainText)) {
|
|
31
|
+
val context = context()
|
|
32
|
+
clipboard(context).setPrimaryClip(ClipData.newPlainText("text", "copied"))
|
|
33
|
+
val events = mutableListOf<Pair<String, String>>()
|
|
34
|
+
val view = view(context, events)
|
|
35
|
+
|
|
36
|
+
assertTrue(view.onTextContextMenuItem(action))
|
|
37
|
+
assertEquals(listOf(ClipDescription.MIMETYPE_TEXT_PLAIN to "copied"), events)
|
|
38
|
+
assertEquals("copied", view.text.toString())
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Test
|
|
43
|
+
fun uriPasteReportsResolvedMime() {
|
|
44
|
+
val context = context()
|
|
45
|
+
val uri = Uri.parse("content://text-input-image/item")
|
|
46
|
+
ShadowContentResolver.registerProviderInternal("text-input-image", MimeProvider("image/png"))
|
|
47
|
+
clipboard(context).setPrimaryClip(uriClip(uri))
|
|
48
|
+
val events = mutableListOf<Pair<String, String>>()
|
|
49
|
+
val view = view(context, events)
|
|
50
|
+
|
|
51
|
+
assertTrue(view.onTextContextMenuItem(R.id.paste))
|
|
52
|
+
assertEquals(listOf("image/png" to uri.toString()), events)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@Test
|
|
56
|
+
fun uriWithoutResolvedMimeDoesNotReport() {
|
|
57
|
+
val context = context()
|
|
58
|
+
val uri = Uri.parse("content://text-input-no-mime/item")
|
|
59
|
+
ShadowContentResolver.registerProviderInternal("text-input-no-mime", MimeProvider(null))
|
|
60
|
+
clipboard(context).setPrimaryClip(uriClip(uri))
|
|
61
|
+
val events = mutableListOf<Pair<String, String>>()
|
|
62
|
+
val view = view(context, events)
|
|
63
|
+
|
|
64
|
+
assertTrue(view.onTextContextMenuItem(R.id.paste))
|
|
65
|
+
assertTrue(events.isEmpty())
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@Test
|
|
69
|
+
fun removedWatcherDoesNotReportButStillRunsNativePaste() {
|
|
70
|
+
val context = context()
|
|
71
|
+
clipboard(context).setPrimaryClip(ClipData.newPlainText("text", "copied"))
|
|
72
|
+
val events = mutableListOf<Pair<String, String>>()
|
|
73
|
+
val view = view(context, events)
|
|
74
|
+
view.setPasteWatcher(null)
|
|
75
|
+
|
|
76
|
+
assertTrue(view.onTextContextMenuItem(R.id.paste))
|
|
77
|
+
assertTrue(events.isEmpty())
|
|
78
|
+
assertEquals("copied", view.text.toString())
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private fun context(): TestReactContext {
|
|
82
|
+
val application = RuntimeEnvironment.getApplication()
|
|
83
|
+
DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(application)
|
|
84
|
+
return TestReactContext(application)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private fun clipboard(context: Context) =
|
|
88
|
+
context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
|
89
|
+
|
|
90
|
+
private fun view(context: Context, events: MutableList<Pair<String, String>>) =
|
|
91
|
+
TextInputView(context).apply {
|
|
92
|
+
setPasteWatcher(object : PasteWatcher {
|
|
93
|
+
override fun onPaste(type: String, data: String) {
|
|
94
|
+
events += type to data
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private fun uriClip(uri: Uri) =
|
|
100
|
+
ClipData(ClipDescription("uri", arrayOf("text/uri-list")), ClipData.Item(uri))
|
|
101
|
+
|
|
102
|
+
private class TestReactContext(base: Context) : BridgeReactContext(base) {
|
|
103
|
+
override fun <T : NativeModule?> getNativeModule(nativeModuleInterface: Class<T>): T? = null
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private class MimeProvider(private val mime: String?) : ContentProvider() {
|
|
107
|
+
override fun onCreate() = true
|
|
108
|
+
override fun getType(uri: Uri): String? = mime
|
|
109
|
+
override fun query(uri: Uri, projection: Array<out String>?, selection: String?,
|
|
110
|
+
selectionArgs: Array<out String>?, sortOrder: String?): Cursor? = null
|
|
111
|
+
override fun insert(uri: Uri, values: ContentValues?): Uri? = null
|
|
112
|
+
override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int = 0
|
|
113
|
+
override fun update(uri: Uri, values: ContentValues?, selection: String?,
|
|
114
|
+
selectionArgs: Array<out String>?): Int = 0
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -54,7 +54,7 @@ static dispatch_semaphore_t OneKeyTestReleaseRead;
|
|
|
54
54
|
}
|
|
55
55
|
static dispatch_once_t onceToken;
|
|
56
56
|
dispatch_once(&onceToken, ^{
|
|
57
|
-
Method original = class_getInstanceMethod(
|
|
57
|
+
Method original = class_getInstanceMethod(object_getClass(pasteboard), @selector(hasImages));
|
|
58
58
|
Method replacement = class_getInstanceMethod(UIPasteboard.class, @selector(onekey_test_hasImages));
|
|
59
59
|
method_exchangeImplementations(original, replacement);
|
|
60
60
|
});
|
|
@@ -64,6 +64,7 @@ static dispatch_semaphore_t OneKeyTestReleaseRead;
|
|
|
64
64
|
[UIColor.blackColor setFill];
|
|
65
65
|
UIRectFill(CGRectMake(0, 0, 1, 1));
|
|
66
66
|
}];
|
|
67
|
+
[NSNotificationCenter.defaultCenter postNotificationName:UIPasteboardChangedNotification object:pasteboard];
|
|
67
68
|
XCTAssertEqual(dispatch_semaphore_wait(OneKeyTestReadStarted, dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC)), 0L);
|
|
68
69
|
|
|
69
70
|
[NSNotificationCenter.defaultCenter postNotificationName:name object:field];
|
package/package.json
CHANGED