@openeditor/react-native-prose-editor 0.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/LICENSE +160 -0
- package/README.md +180 -0
- package/android/build.gradle +69 -0
- package/android/consumer-rules.pro +18 -0
- package/android/src/androidTest/AndroidManifest.xml +8 -0
- package/android/src/androidTest/java/com/apollohg/editor/MeasureHeightInstrumentedTest.kt +53 -0
- package/android/src/androidTest/java/com/apollohg/editor/NativeDeviceCollaborationInitialSyncTest.kt +241 -0
- package/android/src/androidTest/java/com/apollohg/editor/NativeDeviceImeRegressionTest.kt +338 -0
- package/android/src/androidTest/java/com/apollohg/editor/NativeDeviceOutsideTapTest.kt +789 -0
- package/android/src/androidTest/java/com/apollohg/editor/NativeDevicePerformanceTest.kt +350 -0
- package/android/src/androidTest/java/com/apollohg/editor/NativeEditorOutsideTapActivity.kt +5 -0
- package/android/src/main/assets/editor-icons/MaterialIcons.json +2236 -0
- package/android/src/main/assets/editor-icons/MaterialIcons.ttf +0 -0
- package/android/src/main/java/com/apollohg/editor/CaretGeometry.kt +50 -0
- package/android/src/main/java/com/apollohg/editor/EditorAddons.kt +135 -0
- package/android/src/main/java/com/apollohg/editor/EditorEditText.kt +4527 -0
- package/android/src/main/java/com/apollohg/editor/EditorHeightBehavior.kt +14 -0
- package/android/src/main/java/com/apollohg/editor/EditorInputConnection.kt +999 -0
- package/android/src/main/java/com/apollohg/editor/EditorTheme.kt +474 -0
- package/android/src/main/java/com/apollohg/editor/ImageResizeOverlayView.kt +199 -0
- package/android/src/main/java/com/apollohg/editor/NativeEditorExpoView.kt +3137 -0
- package/android/src/main/java/com/apollohg/editor/NativeEditorModule.kt +561 -0
- package/android/src/main/java/com/apollohg/editor/NativeProseViewerExpoView.kt +315 -0
- package/android/src/main/java/com/apollohg/editor/NativeToolbar.kt +1413 -0
- package/android/src/main/java/com/apollohg/editor/PositionBridge.kt +133 -0
- package/android/src/main/java/com/apollohg/editor/RemoteSelectionOverlayView.kt +315 -0
- package/android/src/main/java/com/apollohg/editor/RenderBridge.kt +2172 -0
- package/android/src/main/java/com/apollohg/editor/RichTextEditorView.kt +399 -0
- package/android/src/sharedTest/java/com/apollohg/editor/NativePerformanceSupport.kt +482 -0
- package/android/src/test/java/com/apollohg/editor/CaretGeometryTest.kt +137 -0
- package/android/src/test/java/com/apollohg/editor/EditorEditTextHardwareKeyTest.kt +321 -0
- package/android/src/test/java/com/apollohg/editor/EditorInputConnectionTest.kt +4202 -0
- package/android/src/test/java/com/apollohg/editor/NativeEditorExpoViewTest.kt +2581 -0
- package/android/src/test/java/com/apollohg/editor/NativeEditorModuleTest.kt +27 -0
- package/android/src/test/java/com/apollohg/editor/NativePerformanceTest.kt +197 -0
- package/android/src/test/java/com/apollohg/editor/NativeProseViewerExpoViewTest.kt +84 -0
- package/android/src/test/java/com/apollohg/editor/NativeToolbarTest.kt +544 -0
- package/android/src/test/java/com/apollohg/editor/PositionBridgeTest.kt +461 -0
- package/android/src/test/java/com/apollohg/editor/RenderBridgeTest.kt +2054 -0
- package/android/src/test/java/com/apollohg/editor/RichTextEditorViewTest.kt +1367 -0
- package/app.plugin.js +62 -0
- package/dist/EditorTheme.d.ts +113 -0
- package/dist/EditorTheme.js +29 -0
- package/dist/EditorToolbar.d.ts +191 -0
- package/dist/EditorToolbar.js +1095 -0
- package/dist/NativeEditorBridge.d.ts +325 -0
- package/dist/NativeEditorBridge.js +933 -0
- package/dist/NativeProseViewer.d.ts +53 -0
- package/dist/NativeProseViewer.js +480 -0
- package/dist/NativeRichTextEditor.d.ts +183 -0
- package/dist/NativeRichTextEditor.js +2574 -0
- package/dist/YjsCollaboration.d.ts +90 -0
- package/dist/YjsCollaboration.js +743 -0
- package/dist/addons.d.ts +100 -0
- package/dist/addons.js +82 -0
- package/dist/heightCache.d.ts +6 -0
- package/dist/heightCache.js +45 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +30 -0
- package/dist/schemas.d.ts +37 -0
- package/dist/schemas.js +263 -0
- package/dist/useNativeEditor.d.ts +42 -0
- package/dist/useNativeEditor.js +124 -0
- package/expo-module.config.json +9 -0
- package/ios/EditorAddons.swift +327 -0
- package/ios/EditorCore.xcframework/Info.plist +44 -0
- package/ios/EditorCore.xcframework/ios-arm64/libeditor_core.a +0 -0
- package/ios/EditorCore.xcframework/ios-arm64_x86_64-simulator/libeditor_core.a +0 -0
- package/ios/EditorLayoutManager.swift +774 -0
- package/ios/EditorTheme.swift +515 -0
- package/ios/Generated_editor_core.swift +1513 -0
- package/ios/NativeEditorExpoView.swift +3593 -0
- package/ios/NativeEditorModule.swift +624 -0
- package/ios/NativeProseViewerExpoView.swift +276 -0
- package/ios/PositionBridge.swift +558 -0
- package/ios/ReactNativeProseEditor.podspec +49 -0
- package/ios/RenderBridge.swift +1708 -0
- package/ios/RichTextEditorView.swift +6150 -0
- package/ios/Tests/NativePerformanceTests.swift +687 -0
- package/ios/Tests/PositionBridgeTests.swift +706 -0
- package/ios/Tests/RenderBridgeTests.swift +2236 -0
- package/ios/Tests/RichTextEditorViewTests.swift +6548 -0
- package/ios/editor_coreFFI/editor_coreFFI.h +1289 -0
- package/ios/editor_coreFFI/module.modulemap +7 -0
- package/ios/editor_coreFFI.h +904 -0
- package/ios/editor_coreFFI.modulemap +7 -0
- package/package.json +74 -0
- package/rust/android/arm64-v8a/libeditor_core.so +0 -0
- package/rust/android/armeabi-v7a/libeditor_core.so +0 -0
- package/rust/android/x86_64/libeditor_core.so +0 -0
- package/rust/bindings/kotlin/uniffi/editor_core/editor_core.kt +2563 -0
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
package com.openeditor.editor
|
|
2
|
+
|
|
3
|
+
import android.graphics.Color
|
|
4
|
+
import android.graphics.drawable.ColorDrawable
|
|
5
|
+
import android.os.Looper
|
|
6
|
+
import android.view.View
|
|
7
|
+
import org.junit.Assert.assertNotEquals
|
|
8
|
+
import org.junit.Assert.assertEquals
|
|
9
|
+
import org.junit.Assert.assertFalse
|
|
10
|
+
import org.junit.Assert.assertNotNull
|
|
11
|
+
import org.junit.Assert.assertTrue
|
|
12
|
+
import org.junit.Test
|
|
13
|
+
import org.junit.runner.RunWith
|
|
14
|
+
import org.robolectric.RobolectricTestRunner
|
|
15
|
+
import org.robolectric.RuntimeEnvironment
|
|
16
|
+
import org.robolectric.Shadows.shadowOf
|
|
17
|
+
import org.robolectric.annotation.Config
|
|
18
|
+
|
|
19
|
+
@RunWith(RobolectricTestRunner::class)
|
|
20
|
+
@Config(sdk = [34])
|
|
21
|
+
class NativeToolbarTest {
|
|
22
|
+
|
|
23
|
+
@Test
|
|
24
|
+
fun `toolbar items parse platform material icons and action state`() {
|
|
25
|
+
val items = NativeToolbarItem.fromJson(
|
|
26
|
+
"""
|
|
27
|
+
[
|
|
28
|
+
{
|
|
29
|
+
"type": "action",
|
|
30
|
+
"key": "mention",
|
|
31
|
+
"label": "Mention",
|
|
32
|
+
"icon": {
|
|
33
|
+
"type": "platform",
|
|
34
|
+
"android": { "type": "material", "name": "alternate-email" },
|
|
35
|
+
"fallbackText": "@"
|
|
36
|
+
},
|
|
37
|
+
"isActive": true,
|
|
38
|
+
"isDisabled": false
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
""".trimIndent()
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
assertEquals(1, items.size)
|
|
45
|
+
assertEquals(ToolbarItemKind.action, items[0].type)
|
|
46
|
+
assertEquals("alternate-email", items[0].icon?.resolvedMaterialIconName())
|
|
47
|
+
assertTrue(items[0].isActive)
|
|
48
|
+
assertFalse(items[0].isDisabled)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@Test
|
|
52
|
+
fun `toolbar items parse heading buttons`() {
|
|
53
|
+
val items = NativeToolbarItem.fromJson(
|
|
54
|
+
"""
|
|
55
|
+
[
|
|
56
|
+
{
|
|
57
|
+
"type": "heading",
|
|
58
|
+
"level": 3,
|
|
59
|
+
"label": "Heading 3",
|
|
60
|
+
"icon": { "type": "default", "id": "h3" }
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
""".trimIndent()
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
assertEquals(1, items.size)
|
|
67
|
+
assertEquals(ToolbarItemKind.heading, items[0].type)
|
|
68
|
+
assertEquals(3, items[0].headingLevel)
|
|
69
|
+
assertEquals("H3", items[0].icon?.resolvedGlyphText())
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@Test
|
|
73
|
+
fun `toolbar items parse grouped buttons`() {
|
|
74
|
+
val items = NativeToolbarItem.fromJson(
|
|
75
|
+
"""
|
|
76
|
+
[
|
|
77
|
+
{
|
|
78
|
+
"type": "group",
|
|
79
|
+
"key": "headings",
|
|
80
|
+
"label": "Headings",
|
|
81
|
+
"icon": { "type": "glyph", "text": "H" },
|
|
82
|
+
"presentation": "menu",
|
|
83
|
+
"items": [
|
|
84
|
+
{
|
|
85
|
+
"type": "heading",
|
|
86
|
+
"level": 1,
|
|
87
|
+
"label": "Heading 1",
|
|
88
|
+
"icon": { "type": "default", "id": "h1" }
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"type": "heading",
|
|
92
|
+
"level": 2,
|
|
93
|
+
"label": "Heading 2",
|
|
94
|
+
"icon": { "type": "default", "id": "h2" }
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
]
|
|
99
|
+
""".trimIndent()
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
assertEquals(1, items.size)
|
|
103
|
+
assertEquals(ToolbarItemKind.group, items[0].type)
|
|
104
|
+
assertEquals(ToolbarGroupPresentation.menu, items[0].presentation)
|
|
105
|
+
assertEquals(2, items[0].items.size)
|
|
106
|
+
assertEquals(ToolbarItemKind.heading, items[0].items[0].type)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@Test
|
|
110
|
+
fun `material icon registry resolves glyph and typeface`() {
|
|
111
|
+
val context = RuntimeEnvironment.getApplication()
|
|
112
|
+
val glyph = MaterialIconRegistry.glyphForName(context, "alternate-email")
|
|
113
|
+
val typeface = MaterialIconRegistry.typeface(context)
|
|
114
|
+
|
|
115
|
+
assertNotNull(glyph)
|
|
116
|
+
assertTrue(glyph!!.isNotEmpty())
|
|
117
|
+
assertNotNull(typeface)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@Test
|
|
121
|
+
fun `toolbar state parses allowed marks insertable nodes and history`() {
|
|
122
|
+
val state = NativeToolbarState.fromUpdateJson(
|
|
123
|
+
"""
|
|
124
|
+
{
|
|
125
|
+
"activeState": {
|
|
126
|
+
"marks": { "bold": true },
|
|
127
|
+
"nodes": { "paragraph": true },
|
|
128
|
+
"commands": { "wrapBulletList": true },
|
|
129
|
+
"allowedMarks": ["bold", "italic"],
|
|
130
|
+
"insertableNodes": ["horizontalRule", "hardBreak"]
|
|
131
|
+
},
|
|
132
|
+
"historyState": {
|
|
133
|
+
"canUndo": true,
|
|
134
|
+
"canRedo": false
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
""".trimIndent()
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
requireNotNull(state)
|
|
141
|
+
assertTrue(state.marks["bold"] == true)
|
|
142
|
+
assertTrue(state.allowedMarks.contains("italic"))
|
|
143
|
+
assertTrue(state.insertableNodes.contains("hardBreak"))
|
|
144
|
+
assertTrue(state.commands["wrapBulletList"] == true)
|
|
145
|
+
assertTrue(state.canUndo)
|
|
146
|
+
assertFalse(state.canRedo)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
@Test
|
|
150
|
+
fun `native toolbar heading button uses command and node state`() {
|
|
151
|
+
val context = RuntimeEnvironment.getApplication()
|
|
152
|
+
val toolbar = EditorKeyboardToolbarView(context)
|
|
153
|
+
toolbar.setItems(
|
|
154
|
+
listOf(
|
|
155
|
+
NativeToolbarItem(
|
|
156
|
+
type = ToolbarItemKind.heading,
|
|
157
|
+
label = "Heading 2",
|
|
158
|
+
icon = NativeToolbarIcon(defaultId = ToolbarDefaultIconId.h2),
|
|
159
|
+
headingLevel = 2
|
|
160
|
+
)
|
|
161
|
+
)
|
|
162
|
+
)
|
|
163
|
+
toolbar.applyState(
|
|
164
|
+
NativeToolbarState(
|
|
165
|
+
marks = emptyMap(),
|
|
166
|
+
nodes = mapOf("h2" to true),
|
|
167
|
+
commands = mapOf("toggleHeading2" to true),
|
|
168
|
+
allowedMarks = emptySet(),
|
|
169
|
+
insertableNodes = emptySet(),
|
|
170
|
+
canUndo = false,
|
|
171
|
+
canRedo = false
|
|
172
|
+
)
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
val headingButton = requireNotNull(toolbar.buttonAtForTesting(0))
|
|
176
|
+
assertTrue(headingButton.isEnabled)
|
|
177
|
+
assertNotNull(headingButton.background)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
@Test
|
|
181
|
+
fun `native toolbar expands grouped buttons inline`() {
|
|
182
|
+
val context = RuntimeEnvironment.getApplication()
|
|
183
|
+
val toolbar = EditorKeyboardToolbarView(context)
|
|
184
|
+
toolbar.setItems(
|
|
185
|
+
listOf(
|
|
186
|
+
NativeToolbarItem(
|
|
187
|
+
type = ToolbarItemKind.group,
|
|
188
|
+
key = "headings",
|
|
189
|
+
label = "Headings",
|
|
190
|
+
icon = NativeToolbarIcon(glyphText = "H"),
|
|
191
|
+
presentation = ToolbarGroupPresentation.expand,
|
|
192
|
+
items = listOf(
|
|
193
|
+
NativeToolbarItem(
|
|
194
|
+
type = ToolbarItemKind.heading,
|
|
195
|
+
label = "Heading 1",
|
|
196
|
+
icon = NativeToolbarIcon(defaultId = ToolbarDefaultIconId.h1),
|
|
197
|
+
headingLevel = 1
|
|
198
|
+
),
|
|
199
|
+
NativeToolbarItem(
|
|
200
|
+
type = ToolbarItemKind.heading,
|
|
201
|
+
label = "Heading 2",
|
|
202
|
+
icon = NativeToolbarIcon(defaultId = ToolbarDefaultIconId.h2),
|
|
203
|
+
headingLevel = 2
|
|
204
|
+
)
|
|
205
|
+
)
|
|
206
|
+
)
|
|
207
|
+
)
|
|
208
|
+
)
|
|
209
|
+
toolbar.applyState(
|
|
210
|
+
NativeToolbarState(
|
|
211
|
+
marks = emptyMap(),
|
|
212
|
+
nodes = emptyMap(),
|
|
213
|
+
commands = mapOf("toggleHeading1" to true, "toggleHeading2" to true),
|
|
214
|
+
allowedMarks = emptySet(),
|
|
215
|
+
insertableNodes = emptySet(),
|
|
216
|
+
canUndo = false,
|
|
217
|
+
canRedo = false
|
|
218
|
+
)
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
assertEquals(1, toolbar.buttonCountForTesting())
|
|
222
|
+
|
|
223
|
+
requireNotNull(toolbar.buttonAtForTesting(0)).performClick()
|
|
224
|
+
|
|
225
|
+
assertEquals(3, toolbar.buttonCountForTesting())
|
|
226
|
+
assertEquals("Heading 1", toolbar.buttonAtForTesting(1)?.contentDescription)
|
|
227
|
+
assertEquals("Heading 2", toolbar.buttonAtForTesting(2)?.contentDescription)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
@Test
|
|
231
|
+
fun `native toolbar preserves horizontal scroll offset when expanding grouped buttons`() {
|
|
232
|
+
val context = RuntimeEnvironment.getApplication()
|
|
233
|
+
val toolbar = EditorKeyboardToolbarView(context)
|
|
234
|
+
fun actionItem(key: String, label: String) = NativeToolbarItem(
|
|
235
|
+
type = ToolbarItemKind.action,
|
|
236
|
+
key = key,
|
|
237
|
+
label = label,
|
|
238
|
+
icon = NativeToolbarIcon(glyphText = label)
|
|
239
|
+
)
|
|
240
|
+
toolbar.setItems(
|
|
241
|
+
listOf(
|
|
242
|
+
actionItem("bold", "B"),
|
|
243
|
+
actionItem("italic", "I"),
|
|
244
|
+
actionItem("underline", "U"),
|
|
245
|
+
NativeToolbarItem(
|
|
246
|
+
type = ToolbarItemKind.group,
|
|
247
|
+
key = "headings",
|
|
248
|
+
label = "Headings",
|
|
249
|
+
icon = NativeToolbarIcon(glyphText = "H"),
|
|
250
|
+
presentation = ToolbarGroupPresentation.expand,
|
|
251
|
+
items = listOf(
|
|
252
|
+
actionItem("h1", "H1"),
|
|
253
|
+
actionItem("h2", "H2")
|
|
254
|
+
)
|
|
255
|
+
),
|
|
256
|
+
actionItem("redo", "R"),
|
|
257
|
+
actionItem("undo", "U2")
|
|
258
|
+
)
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
val widthSpec = View.MeasureSpec.makeMeasureSpec(140, View.MeasureSpec.EXACTLY)
|
|
262
|
+
val heightSpec = View.MeasureSpec.makeMeasureSpec(64, View.MeasureSpec.EXACTLY)
|
|
263
|
+
toolbar.measure(widthSpec, heightSpec)
|
|
264
|
+
toolbar.layout(0, 0, 140, 64)
|
|
265
|
+
|
|
266
|
+
toolbar.scrollTo(48, 0)
|
|
267
|
+
assertEquals(48, toolbar.scrollX)
|
|
268
|
+
|
|
269
|
+
requireNotNull(toolbar.buttonAtForTesting(3)).performClick()
|
|
270
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
271
|
+
toolbar.measure(widthSpec, heightSpec)
|
|
272
|
+
toolbar.layout(0, 0, 140, 64)
|
|
273
|
+
|
|
274
|
+
assertEquals(48, toolbar.scrollX)
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
@Test
|
|
278
|
+
fun `toolbar theme parses native appearance`() {
|
|
279
|
+
val theme = EditorToolbarTheme.fromJson(
|
|
280
|
+
org.json.JSONObject(
|
|
281
|
+
"""
|
|
282
|
+
{
|
|
283
|
+
"appearance": "native",
|
|
284
|
+
"height": 44
|
|
285
|
+
}
|
|
286
|
+
""".trimIndent()
|
|
287
|
+
)
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
assertEquals(EditorToolbarAppearance.NATIVE, theme?.appearance)
|
|
291
|
+
assertEquals(44f, theme?.height)
|
|
292
|
+
assertEquals(8f, theme?.resolvedKeyboardOffset())
|
|
293
|
+
assertEquals(0f, theme?.resolvedHorizontalInset())
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
@Test
|
|
297
|
+
fun `toolbar switches to mention suggestion mode`() {
|
|
298
|
+
val context = RuntimeEnvironment.getApplication()
|
|
299
|
+
val toolbar = EditorKeyboardToolbarView(context)
|
|
300
|
+
|
|
301
|
+
toolbar.applyMentionTheme(
|
|
302
|
+
EditorMentionTheme.fromJson(
|
|
303
|
+
org.json.JSONObject(
|
|
304
|
+
"""
|
|
305
|
+
{
|
|
306
|
+
"backgroundColor": "#d7e4ff",
|
|
307
|
+
"optionTextColor": "#1a2c48"
|
|
308
|
+
}
|
|
309
|
+
""".trimIndent()
|
|
310
|
+
)
|
|
311
|
+
)
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
val didChange = toolbar.setMentionSuggestions(
|
|
315
|
+
listOf(
|
|
316
|
+
NativeMentionSuggestion(
|
|
317
|
+
key = "alice",
|
|
318
|
+
title = "Alice Chen",
|
|
319
|
+
subtitle = "Design",
|
|
320
|
+
label = "@alice",
|
|
321
|
+
attrs = org.json.JSONObject().put("id", "user_alice")
|
|
322
|
+
)
|
|
323
|
+
)
|
|
324
|
+
)
|
|
325
|
+
|
|
326
|
+
assertTrue(didChange)
|
|
327
|
+
assertTrue(toolbar.isShowingMentionSuggestions)
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
@Test
|
|
331
|
+
fun `toolbar mention suggestion tap invokes callback and clears back to button mode`() {
|
|
332
|
+
val context = RuntimeEnvironment.getApplication()
|
|
333
|
+
val toolbar = EditorKeyboardToolbarView(context)
|
|
334
|
+
val suggestion = NativeMentionSuggestion(
|
|
335
|
+
key = "alice",
|
|
336
|
+
title = "Alice Chen",
|
|
337
|
+
subtitle = "Design",
|
|
338
|
+
label = "@alice",
|
|
339
|
+
attrs = org.json.JSONObject().put("id", "user_alice")
|
|
340
|
+
)
|
|
341
|
+
var selectedKey: String? = null
|
|
342
|
+
toolbar.onSelectMentionSuggestion = { selected ->
|
|
343
|
+
selectedKey = selected.key
|
|
344
|
+
}
|
|
345
|
+
toolbar.setMentionSuggestions(listOf(suggestion))
|
|
346
|
+
|
|
347
|
+
val widthSpec = View.MeasureSpec.makeMeasureSpec(480, View.MeasureSpec.AT_MOST)
|
|
348
|
+
val heightSpec = View.MeasureSpec.makeMeasureSpec(120, View.MeasureSpec.AT_MOST)
|
|
349
|
+
toolbar.measure(widthSpec, heightSpec)
|
|
350
|
+
toolbar.layout(0, 0, toolbar.measuredWidth, toolbar.measuredHeight)
|
|
351
|
+
toolbar.triggerMentionSuggestionTapForTesting(0)
|
|
352
|
+
|
|
353
|
+
assertEquals("alice", selectedKey)
|
|
354
|
+
|
|
355
|
+
val didChange = toolbar.setMentionSuggestions(emptyList())
|
|
356
|
+
|
|
357
|
+
assertTrue(didChange)
|
|
358
|
+
assertFalse(toolbar.isShowingMentionSuggestions)
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
@Test
|
|
362
|
+
fun `native toolbar applies native appearance to mention suggestions`() {
|
|
363
|
+
val context = RuntimeEnvironment.getApplication()
|
|
364
|
+
val toolbar = EditorKeyboardToolbarView(context)
|
|
365
|
+
toolbar.applyTheme(
|
|
366
|
+
EditorToolbarTheme(
|
|
367
|
+
appearance = EditorToolbarAppearance.NATIVE
|
|
368
|
+
)
|
|
369
|
+
)
|
|
370
|
+
toolbar.setMentionSuggestions(
|
|
371
|
+
listOf(
|
|
372
|
+
NativeMentionSuggestion(
|
|
373
|
+
key = "alice",
|
|
374
|
+
title = "Alice Chen",
|
|
375
|
+
subtitle = "Design",
|
|
376
|
+
label = "@alice",
|
|
377
|
+
attrs = org.json.JSONObject().put("id", "user_alice")
|
|
378
|
+
)
|
|
379
|
+
)
|
|
380
|
+
)
|
|
381
|
+
|
|
382
|
+
assertTrue(toolbar.mentionChipAtForTesting(0)?.usesNativeAppearanceForTesting() == true)
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
@Test
|
|
386
|
+
fun `toolbar theme dimensions are applied in density scaled pixels without elevation`() {
|
|
387
|
+
val context = RuntimeEnvironment.getApplication()
|
|
388
|
+
val density = context.resources.displayMetrics.density
|
|
389
|
+
val toolbar = EditorKeyboardToolbarView(context)
|
|
390
|
+
|
|
391
|
+
toolbar.applyTheme(
|
|
392
|
+
EditorToolbarTheme(
|
|
393
|
+
borderWidth = 2f,
|
|
394
|
+
borderRadius = 20f,
|
|
395
|
+
buttonBorderRadius = 14f
|
|
396
|
+
)
|
|
397
|
+
)
|
|
398
|
+
|
|
399
|
+
assertEquals(0f, toolbar.elevation)
|
|
400
|
+
assertEquals(20f * density, toolbar.appliedChromeCornerRadiusPx)
|
|
401
|
+
assertEquals((2f * density).toInt().coerceAtLeast(1), toolbar.appliedChromeStrokeWidthPx)
|
|
402
|
+
assertEquals(14f * density, toolbar.appliedButtonCornerRadiusPx)
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
@Test
|
|
406
|
+
fun `native toolbar appearance uses docked material chrome defaults`() {
|
|
407
|
+
val context = RuntimeEnvironment.getApplication()
|
|
408
|
+
val density = context.resources.displayMetrics.density
|
|
409
|
+
val toolbar = EditorKeyboardToolbarView(context)
|
|
410
|
+
|
|
411
|
+
toolbar.applyTheme(
|
|
412
|
+
EditorToolbarTheme(
|
|
413
|
+
appearance = EditorToolbarAppearance.NATIVE
|
|
414
|
+
)
|
|
415
|
+
)
|
|
416
|
+
|
|
417
|
+
assertEquals(EditorToolbarAppearance.NATIVE, toolbar.appliedAppearance)
|
|
418
|
+
assertEquals(0, toolbar.appliedChromeStrokeWidthPx)
|
|
419
|
+
assertEquals(32f * density, toolbar.appliedChromeCornerRadiusPx)
|
|
420
|
+
assertEquals(20f * density, toolbar.appliedButtonCornerRadiusPx)
|
|
421
|
+
assertEquals(0f, toolbar.appliedChromeElevationPx)
|
|
422
|
+
assertTrue(toolbar.clipToOutline)
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
@Test
|
|
426
|
+
fun `native toolbar separators remain visible`() {
|
|
427
|
+
val context = RuntimeEnvironment.getApplication()
|
|
428
|
+
val toolbar = EditorKeyboardToolbarView(context)
|
|
429
|
+
|
|
430
|
+
toolbar.applyTheme(
|
|
431
|
+
EditorToolbarTheme(
|
|
432
|
+
appearance = EditorToolbarAppearance.NATIVE
|
|
433
|
+
)
|
|
434
|
+
)
|
|
435
|
+
|
|
436
|
+
val separator = requireNotNull(toolbar.separatorAtForTesting(0))
|
|
437
|
+
val separatorDrawable = separator.background as? ColorDrawable
|
|
438
|
+
|
|
439
|
+
assertEquals(1, separator.layoutParams.width)
|
|
440
|
+
assertNotNull(separatorDrawable)
|
|
441
|
+
assertNotEquals(Color.TRANSPARENT, separatorDrawable?.color)
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
@Test
|
|
445
|
+
fun `native toolbar updates button selected and disabled colors from state`() {
|
|
446
|
+
val context = RuntimeEnvironment.getApplication()
|
|
447
|
+
val toolbar = EditorKeyboardToolbarView(context)
|
|
448
|
+
toolbar.applyTheme(
|
|
449
|
+
EditorToolbarTheme(
|
|
450
|
+
appearance = EditorToolbarAppearance.NATIVE
|
|
451
|
+
)
|
|
452
|
+
)
|
|
453
|
+
|
|
454
|
+
toolbar.applyState(
|
|
455
|
+
NativeToolbarState(
|
|
456
|
+
marks = emptyMap(),
|
|
457
|
+
nodes = emptyMap(),
|
|
458
|
+
commands = emptyMap(),
|
|
459
|
+
allowedMarks = setOf("bold"),
|
|
460
|
+
insertableNodes = emptySet(),
|
|
461
|
+
canUndo = false,
|
|
462
|
+
canRedo = false
|
|
463
|
+
)
|
|
464
|
+
)
|
|
465
|
+
|
|
466
|
+
val boldButton = requireNotNull(toolbar.buttonAtForTesting(0))
|
|
467
|
+
val inactiveColor = boldButton.currentTextColor
|
|
468
|
+
|
|
469
|
+
toolbar.applyState(
|
|
470
|
+
NativeToolbarState(
|
|
471
|
+
marks = mapOf("bold" to true),
|
|
472
|
+
nodes = emptyMap(),
|
|
473
|
+
commands = emptyMap(),
|
|
474
|
+
allowedMarks = setOf("bold"),
|
|
475
|
+
insertableNodes = emptySet(),
|
|
476
|
+
canUndo = false,
|
|
477
|
+
canRedo = false
|
|
478
|
+
)
|
|
479
|
+
)
|
|
480
|
+
|
|
481
|
+
assertTrue(boldButton.isSelected)
|
|
482
|
+
assertNotEquals(inactiveColor, boldButton.currentTextColor)
|
|
483
|
+
assertEquals(1f, boldButton.alpha)
|
|
484
|
+
|
|
485
|
+
toolbar.applyState(
|
|
486
|
+
NativeToolbarState(
|
|
487
|
+
marks = emptyMap(),
|
|
488
|
+
nodes = emptyMap(),
|
|
489
|
+
commands = emptyMap(),
|
|
490
|
+
allowedMarks = emptySet(),
|
|
491
|
+
insertableNodes = emptySet(),
|
|
492
|
+
canUndo = false,
|
|
493
|
+
canRedo = false
|
|
494
|
+
)
|
|
495
|
+
)
|
|
496
|
+
|
|
497
|
+
assertFalse(boldButton.isEnabled)
|
|
498
|
+
assertEquals(1f, boldButton.alpha)
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
@Test
|
|
502
|
+
@Config(sdk = [34], qualifiers = "night")
|
|
503
|
+
fun `native toolbar resolves non-transparent colors in dark mode`() {
|
|
504
|
+
val context = RuntimeEnvironment.getApplication()
|
|
505
|
+
val toolbar = EditorKeyboardToolbarView(context)
|
|
506
|
+
|
|
507
|
+
toolbar.applyTheme(
|
|
508
|
+
EditorToolbarTheme(
|
|
509
|
+
appearance = EditorToolbarAppearance.NATIVE
|
|
510
|
+
)
|
|
511
|
+
)
|
|
512
|
+
toolbar.applyState(
|
|
513
|
+
NativeToolbarState(
|
|
514
|
+
marks = emptyMap(),
|
|
515
|
+
nodes = emptyMap(),
|
|
516
|
+
commands = emptyMap(),
|
|
517
|
+
allowedMarks = setOf("bold"),
|
|
518
|
+
insertableNodes = emptySet(),
|
|
519
|
+
canUndo = false,
|
|
520
|
+
canRedo = false
|
|
521
|
+
)
|
|
522
|
+
)
|
|
523
|
+
|
|
524
|
+
val boldButton = requireNotNull(toolbar.buttonAtForTesting(0))
|
|
525
|
+
val inactiveColor = boldButton.currentTextColor
|
|
526
|
+
assertNotEquals(Color.TRANSPARENT, toolbar.appliedChromeColor)
|
|
527
|
+
assertNotEquals(Color.TRANSPARENT, inactiveColor)
|
|
528
|
+
|
|
529
|
+
toolbar.applyState(
|
|
530
|
+
NativeToolbarState(
|
|
531
|
+
marks = mapOf("bold" to true),
|
|
532
|
+
nodes = emptyMap(),
|
|
533
|
+
commands = emptyMap(),
|
|
534
|
+
allowedMarks = setOf("bold"),
|
|
535
|
+
insertableNodes = emptySet(),
|
|
536
|
+
canUndo = false,
|
|
537
|
+
canRedo = false
|
|
538
|
+
)
|
|
539
|
+
)
|
|
540
|
+
|
|
541
|
+
assertNotEquals(inactiveColor, boldButton.currentTextColor)
|
|
542
|
+
assertNotEquals(Color.TRANSPARENT, toolbar.buttonBackgroundColorAtForTesting(0))
|
|
543
|
+
}
|
|
544
|
+
}
|