@openeditor/react-native-prose-editor 0.0.7 → 0.0.8
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 +35 -0
- package/android/src/main/java/com/apollohg/editor/CaretGeometry.kt +2 -2
- package/android/src/main/java/com/apollohg/editor/EditorEditText.kt +138 -597
- package/android/src/main/java/com/apollohg/editor/EditorInputConnection.kt +13 -3
- package/android/src/main/java/com/apollohg/editor/InputSnapshotSupport.kt +6 -0
- package/android/src/main/java/com/apollohg/editor/NativeBlockEditorSurface.kt +1086 -0
- package/android/src/main/java/com/apollohg/editor/NativeEditorExpoView.kt +1 -1
- package/android/src/main/java/com/apollohg/editor/NativeEditorModule.kt +26 -50
- package/android/src/main/java/com/apollohg/editor/NativeImageLoader.kt +89 -0
- package/android/src/main/java/com/apollohg/editor/RemoteSelectionOverlayView.kt +31 -66
- package/android/src/main/java/com/apollohg/editor/RichTextEditorView.kt +98 -33
- package/dist/EditorToolbar.d.ts +1 -1
- package/dist/EditorToolbar.js +19 -0
- package/dist/NativeEditorBridge.d.ts +62 -35
- package/dist/NativeEditorBridge.js +122 -79
- package/dist/NativeProseViewer.d.ts +13 -34
- package/dist/NativeProseViewer.js +40 -465
- package/dist/NativeRichTextEditor.d.ts +10 -1
- package/dist/NativeRichTextEditor.js +72 -34
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/dist/schemas.d.ts +11 -0
- package/dist/schemas.js +149 -0
- package/dist/useNativeEditor.d.ts +3 -3
- package/dist/useNativeEditor.js +3 -3
- 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/Generated_editor_core.swift +97 -2
- package/ios/NativeBlockEditorSurface.swift +1393 -0
- package/ios/NativeEditorExpoView.swift +3 -3
- package/ios/NativeEditorModule.swift +30 -45
- package/ios/NativeInputSupport.swift +396 -0
- package/ios/PositionBridge.swift +4 -4
- package/ios/RichTextEditorView.swift +333 -786
- package/ios/editor_coreFFI/editor_coreFFI.h +147 -70
- package/package.json +1 -1
- 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 +2087 -1399
- package/android/src/androidTest/AndroidManifest.xml +0 -8
- package/android/src/androidTest/java/com/apollohg/editor/MeasureHeightInstrumentedTest.kt +0 -53
- package/android/src/androidTest/java/com/apollohg/editor/NativeDeviceCollaborationInitialSyncTest.kt +0 -241
- package/android/src/androidTest/java/com/apollohg/editor/NativeDeviceImeRegressionTest.kt +0 -338
- package/android/src/androidTest/java/com/apollohg/editor/NativeDeviceOutsideTapTest.kt +0 -789
- package/android/src/androidTest/java/com/apollohg/editor/NativeDevicePerformanceTest.kt +0 -350
- package/android/src/androidTest/java/com/apollohg/editor/NativeEditorOutsideTapActivity.kt +0 -5
- package/android/src/main/java/com/apollohg/editor/NativeProseViewerExpoView.kt +0 -315
- package/android/src/main/java/com/apollohg/editor/RenderBridge.kt +0 -2172
- package/android/src/sharedTest/java/com/apollohg/editor/NativePerformanceSupport.kt +0 -482
- package/android/src/test/java/com/apollohg/editor/CaretGeometryTest.kt +0 -137
- package/android/src/test/java/com/apollohg/editor/EditorEditTextHardwareKeyTest.kt +0 -321
- package/android/src/test/java/com/apollohg/editor/EditorInputConnectionTest.kt +0 -4202
- package/android/src/test/java/com/apollohg/editor/NativeEditorExpoViewTest.kt +0 -2581
- package/android/src/test/java/com/apollohg/editor/NativeEditorModuleTest.kt +0 -27
- package/android/src/test/java/com/apollohg/editor/NativePerformanceTest.kt +0 -197
- package/android/src/test/java/com/apollohg/editor/NativeProseViewerExpoViewTest.kt +0 -84
- package/android/src/test/java/com/apollohg/editor/NativeToolbarTest.kt +0 -544
- package/android/src/test/java/com/apollohg/editor/PositionBridgeTest.kt +0 -461
- package/android/src/test/java/com/apollohg/editor/RenderBridgeTest.kt +0 -2054
- package/android/src/test/java/com/apollohg/editor/RichTextEditorViewTest.kt +0 -1367
- package/ios/EditorLayoutManager.swift +0 -774
- package/ios/NativeProseViewerExpoView.swift +0 -276
- package/ios/RenderBridge.swift +0 -1708
- package/ios/Tests/NativePerformanceTests.swift +0 -687
- package/ios/Tests/PositionBridgeTests.swift +0 -706
- package/ios/Tests/RenderBridgeTests.swift +0 -2236
- package/ios/Tests/RichTextEditorViewTests.swift +0 -6548
|
@@ -1,544 +0,0 @@
|
|
|
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
|
-
}
|