@cometchat/chat-uikit-react-native 5.2.10 → 5.3.0
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 +3 -0
- package/android/src/main/java/com/reactnativecometchatuikit/CometchatUiKitPackage.java +4 -1
- package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +909 -10
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorPackage.kt +24 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +5382 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +452 -0
- package/ios/FileManager.m +430 -3
- package/ios/RichTextEditorView.swift +5504 -0
- package/ios/RichTextEditorViewManager.m +66 -0
- package/ios/RichTextEditorViewManager.swift +291 -0
- package/ios/ToolbarIcons.swift +736 -0
- package/package.json +1 -1
- package/react-native-cometchat-ui-kit.podspec +1 -1
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +4557 -0
- package/src/CometChatCompactMessageComposer/SingleLineTextComposerConfiguration.tsx +568 -0
- package/src/CometChatCompactMessageComposer/heightUtils.ts +204 -0
- package/src/CometChatCompactMessageComposer/index.ts +56 -0
- package/src/CometChatCompactMessageComposer/resources/index.ts +5 -0
- package/src/CometChatCompactMessageComposer/styles.ts +291 -0
- package/src/CometChatConversations/CometChatConversations.tsx +139 -10
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +25 -21
- package/src/CometChatMessageComposer/styles.tsx +0 -1
- package/src/CometChatMessageList/CometChatMessageList.tsx +39 -6
- package/src/CometChatMessageList/components/MessageListItem.tsx +11 -8
- package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +105 -0
- package/src/CometChatRichTextEditor/index.tsx +385 -0
- package/src/CometChatRichTextEditor/types.ts +162 -0
- package/src/CometChatSearch/CometChatSearch.tsx +8 -3
- package/src/CometChatSearch/style.ts +3 -3
- package/src/index.ts +48 -1
- package/src/shared/constants/UIKitConstants.ts +12 -1
- package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +5 -5
- package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +768 -0
- package/src/shared/formatters/index.ts +3 -0
- package/src/shared/framework/MessageDataSource.tsx +93 -2
- package/src/shared/helper/composerHelpers.ts +553 -0
- package/src/shared/helper/useKeyboard.tsx +7 -17
- package/src/shared/icons/components/code-blocks.tsx +13 -0
- package/src/shared/icons/components/code.tsx +11 -0
- package/src/shared/icons/components/format-bold.tsx +11 -0
- package/src/shared/icons/components/format-italic.tsx +11 -0
- package/src/shared/icons/components/format-list-bulleted.tsx +11 -0
- package/src/shared/icons/components/format-list-numbered.tsx +11 -0
- package/src/shared/icons/components/format-quote.tsx +13 -0
- package/src/shared/icons/components/format-strikethrough.tsx +13 -0
- package/src/shared/icons/components/format-underlined.tsx +11 -0
- package/src/shared/icons/components/smileys-&-people.tsx +1 -1
- package/src/shared/icons/icon-mapping.tsx +18 -0
- package/src/shared/index.ts +54 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +38 -32
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +6 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +18 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +505 -499
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +19 -13
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +18 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +504 -498
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +504 -498
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +504 -498
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +19 -13
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +18 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +505 -499
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +18 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +18 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +19 -13
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +505 -499
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +18 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +19 -13
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +132 -11
- package/src/shared/utils/CometChatMessagePreview/style.ts +1 -3
- package/src/shared/utils/MarkdownUtils.ts +143 -0
- package/src/shared/utils/MentionUtils.ts +37 -0
- package/src/shared/utils/MessageUtils.tsx +55 -0
- package/src/shared/utils/index.ts +5 -0
- package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +1 -1
- package/src/shared/views/CometChatInlineAudioRecorder/AudioWaveformVisualizer.tsx +417 -0
- package/src/shared/views/CometChatInlineAudioRecorder/CometChatInlineAudioRecorder.tsx +537 -0
- package/src/shared/views/CometChatInlineAudioRecorder/index.ts +34 -0
- package/src/shared/views/CometChatInlineAudioRecorder/style.ts +155 -0
- package/src/shared/views/CometChatInlineAudioRecorder/types.ts +303 -0
- package/src/shared/views/CometChatInlineAudioRecorder/useAudioRecorder.ts +1336 -0
- package/src/shared/views/CometChatLinkConfirmPopup/CometChatLinkConfirmPopup.tsx +183 -0
- package/src/shared/views/CometChatLinkConfirmPopup/index.ts +13 -0
- package/src/shared/views/CometChatLinkConfirmPopup/style.ts +128 -0
- package/src/shared/views/CometChatList/Header.tsx +57 -49
- package/src/shared/views/CometChatMediaRecorder/CometChatMediaRecorder.tsx +0 -1
- package/src/shared/views/CometChatQuickReactions/QuickReactionsStyle.tsx +2 -2
- package/src/shared/views/CometChatReactionList/ReactionListStyle.tsx +3 -2
- package/src/shared/views/CometChatReactions/CometChatReactions.tsx +11 -5
- package/src/shared/views/CometChatReactions/style.ts +35 -8
- package/src/shared/views/CometChatSendButtonView/CometChatSendButtonView.tsx +32 -29
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +108 -75
- package/src/shared/views/index.ts +39 -0
- package/src/theme/index.ts +1 -1
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
package com.reactnativecometchatuikit
|
|
2
|
+
|
|
3
|
+
import android.graphics.Color
|
|
4
|
+
import android.view.View
|
|
5
|
+
import android.view.ViewGroup
|
|
6
|
+
import android.widget.LinearLayout
|
|
7
|
+
import com.facebook.react.bridge.ReadableArray
|
|
8
|
+
import com.facebook.react.bridge.ReadableMap
|
|
9
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
10
|
+
import com.facebook.react.uimanager.SimpleViewManager
|
|
11
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
12
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
13
|
+
|
|
14
|
+
@ReactModule(name = RichTextEditorViewManager.NAME)
|
|
15
|
+
class RichTextEditorViewManager : SimpleViewManager<LinearLayout>() {
|
|
16
|
+
|
|
17
|
+
companion object {
|
|
18
|
+
const val NAME = "RichTextEditorView"
|
|
19
|
+
const val COMMAND_FOCUS = "focus"
|
|
20
|
+
const val COMMAND_BLUR = "blur"
|
|
21
|
+
const val COMMAND_CLEAR = "clear"
|
|
22
|
+
const val COMMAND_TOGGLE_BOLD = "toggleBold"
|
|
23
|
+
const val COMMAND_TOGGLE_ITALIC = "toggleItalic"
|
|
24
|
+
const val COMMAND_TOGGLE_UNDERLINE = "toggleUnderline"
|
|
25
|
+
const val COMMAND_TOGGLE_STRIKETHROUGH = "toggleStrikethrough"
|
|
26
|
+
const val COMMAND_TOGGLE_CODE = "toggleCode"
|
|
27
|
+
const val COMMAND_TOGGLE_CODE_BLOCK = "toggleCodeBlock"
|
|
28
|
+
const val COMMAND_TOGGLE_HIGHLIGHT = "toggleHighlight"
|
|
29
|
+
const val COMMAND_SET_HEADING = "setHeading"
|
|
30
|
+
const val COMMAND_SET_BULLET_LIST = "setBulletList"
|
|
31
|
+
const val COMMAND_SET_NUMBERED_LIST = "setNumberedList"
|
|
32
|
+
const val COMMAND_SET_QUOTE = "setQuote"
|
|
33
|
+
const val COMMAND_SET_CHECKLIST = "setChecklist"
|
|
34
|
+
const val COMMAND_SET_PARAGRAPH = "setParagraph"
|
|
35
|
+
const val COMMAND_INSERT_LINK = "insertLink"
|
|
36
|
+
const val COMMAND_UNDO = "undo"
|
|
37
|
+
const val COMMAND_REDO = "redo"
|
|
38
|
+
const val COMMAND_CLEAR_FORMATTING = "clearFormatting"
|
|
39
|
+
const val COMMAND_INDENT = "indent"
|
|
40
|
+
const val COMMAND_OUTDENT = "outdent"
|
|
41
|
+
const val COMMAND_ALIGN_LEFT = "alignLeft"
|
|
42
|
+
const val COMMAND_ALIGN_CENTER = "alignCenter"
|
|
43
|
+
const val COMMAND_ALIGN_RIGHT = "alignRight"
|
|
44
|
+
const val COMMAND_TOGGLE_CHECKLIST_ITEM = "toggleChecklistItem"
|
|
45
|
+
const val COMMAND_SET_TEXT = "setText"
|
|
46
|
+
const val COMMAND_SET_SELECTION = "setSelection"
|
|
47
|
+
const val COMMAND_SET_CONTENT = "setContent"
|
|
48
|
+
const val COMMAND_SET_MENTION_RANGES = "setMentionRanges"
|
|
49
|
+
const val COMMAND_REMOVE_LINK = "removeLink"
|
|
50
|
+
const val COMMAND_UPDATE_LINK = "updateLink"
|
|
51
|
+
|
|
52
|
+
private const val TAG_EDITOR = "editor"
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
override fun getName(): String = NAME
|
|
56
|
+
|
|
57
|
+
override fun createViewInstance(reactContext: ThemedReactContext): LinearLayout {
|
|
58
|
+
val container = LinearLayout(reactContext).apply {
|
|
59
|
+
orientation = LinearLayout.VERTICAL
|
|
60
|
+
layoutParams = ViewGroup.LayoutParams(
|
|
61
|
+
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
62
|
+
ViewGroup.LayoutParams.WRAP_CONTENT
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
val editor = RichTextEditorView(reactContext)
|
|
67
|
+
editor.tag = TAG_EDITOR
|
|
68
|
+
editor.containerView = container
|
|
69
|
+
editor.layoutParams = LinearLayout.LayoutParams(
|
|
70
|
+
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
71
|
+
ViewGroup.LayoutParams.WRAP_CONTENT,
|
|
72
|
+
1f
|
|
73
|
+
)
|
|
74
|
+
container.addView(editor)
|
|
75
|
+
|
|
76
|
+
return container
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Track showToolbar prop value for proper inline toolbar visibility */
|
|
80
|
+
private val showToolbarState = mutableMapOf<Int, Boolean>()
|
|
81
|
+
|
|
82
|
+
/** Helper to find the editor child inside the container */
|
|
83
|
+
private fun getEditor(container: LinearLayout): RichTextEditorView? {
|
|
84
|
+
for (i in 0 until container.childCount) {
|
|
85
|
+
val child = container.getChildAt(i)
|
|
86
|
+
if (child.tag == TAG_EDITOR && child is RichTextEditorView) {
|
|
87
|
+
return child
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return null
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
override fun getCommandsMap(): Map<String, Int> {
|
|
94
|
+
return mapOf(
|
|
95
|
+
COMMAND_FOCUS to 1,
|
|
96
|
+
COMMAND_BLUR to 2,
|
|
97
|
+
COMMAND_CLEAR to 3,
|
|
98
|
+
COMMAND_TOGGLE_BOLD to 4,
|
|
99
|
+
COMMAND_TOGGLE_ITALIC to 5,
|
|
100
|
+
COMMAND_TOGGLE_UNDERLINE to 6,
|
|
101
|
+
COMMAND_TOGGLE_STRIKETHROUGH to 7,
|
|
102
|
+
COMMAND_TOGGLE_CODE to 8,
|
|
103
|
+
COMMAND_TOGGLE_CODE_BLOCK to 28,
|
|
104
|
+
COMMAND_TOGGLE_HIGHLIGHT to 9,
|
|
105
|
+
COMMAND_SET_HEADING to 10,
|
|
106
|
+
COMMAND_SET_BULLET_LIST to 11,
|
|
107
|
+
COMMAND_SET_NUMBERED_LIST to 12,
|
|
108
|
+
COMMAND_SET_QUOTE to 13,
|
|
109
|
+
COMMAND_SET_CHECKLIST to 14,
|
|
110
|
+
COMMAND_SET_PARAGRAPH to 15,
|
|
111
|
+
COMMAND_INSERT_LINK to 16,
|
|
112
|
+
COMMAND_UNDO to 17,
|
|
113
|
+
COMMAND_REDO to 18,
|
|
114
|
+
COMMAND_CLEAR_FORMATTING to 19,
|
|
115
|
+
COMMAND_INDENT to 20,
|
|
116
|
+
COMMAND_OUTDENT to 21,
|
|
117
|
+
COMMAND_ALIGN_LEFT to 22,
|
|
118
|
+
COMMAND_ALIGN_CENTER to 23,
|
|
119
|
+
COMMAND_ALIGN_RIGHT to 24,
|
|
120
|
+
COMMAND_TOGGLE_CHECKLIST_ITEM to 25,
|
|
121
|
+
COMMAND_SET_TEXT to 26,
|
|
122
|
+
COMMAND_SET_SELECTION to 27,
|
|
123
|
+
COMMAND_SET_CONTENT to 29,
|
|
124
|
+
COMMAND_SET_MENTION_RANGES to 30,
|
|
125
|
+
COMMAND_REMOVE_LINK to 31,
|
|
126
|
+
COMMAND_UPDATE_LINK to 32
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
override fun receiveCommand(container: LinearLayout, commandId: String, args: ReadableArray?) {
|
|
131
|
+
val view = getEditor(container) ?: return
|
|
132
|
+
when (commandId) {
|
|
133
|
+
COMMAND_FOCUS -> view.focusEditor()
|
|
134
|
+
COMMAND_BLUR -> view.blurEditor()
|
|
135
|
+
COMMAND_CLEAR -> view.clearContent()
|
|
136
|
+
else -> {
|
|
137
|
+
if (!view.hasFocus()) {
|
|
138
|
+
view.requestFocus()
|
|
139
|
+
}
|
|
140
|
+
when (commandId) {
|
|
141
|
+
COMMAND_TOGGLE_BOLD -> view.onBoldClick()
|
|
142
|
+
COMMAND_TOGGLE_ITALIC -> view.onItalicClick()
|
|
143
|
+
COMMAND_TOGGLE_UNDERLINE -> view.onUnderlineClick()
|
|
144
|
+
COMMAND_TOGGLE_STRIKETHROUGH -> view.onStrikethroughClick()
|
|
145
|
+
COMMAND_TOGGLE_CODE -> view.onCodeClick()
|
|
146
|
+
COMMAND_TOGGLE_CODE_BLOCK -> view.toggleCodeBlock()
|
|
147
|
+
COMMAND_TOGGLE_HIGHLIGHT -> view.onHighlightClick()
|
|
148
|
+
COMMAND_SET_HEADING -> view.onHeadingClick()
|
|
149
|
+
COMMAND_SET_BULLET_LIST -> view.onBulletListClick()
|
|
150
|
+
COMMAND_SET_NUMBERED_LIST -> view.onNumberedListClick()
|
|
151
|
+
COMMAND_SET_QUOTE -> view.onQuoteClick()
|
|
152
|
+
COMMAND_SET_CHECKLIST -> view.onChecklistClick()
|
|
153
|
+
COMMAND_SET_PARAGRAPH -> { }
|
|
154
|
+
COMMAND_INSERT_LINK -> {
|
|
155
|
+
val url = args?.getString(0) ?: ""
|
|
156
|
+
val linkText = args?.getString(1) ?: ""
|
|
157
|
+
if (url.isNotEmpty() && linkText.isNotEmpty()) {
|
|
158
|
+
view.insertLink(url, linkText)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
COMMAND_UNDO -> view.onUndoClick()
|
|
162
|
+
COMMAND_REDO -> view.onRedoClick()
|
|
163
|
+
COMMAND_CLEAR_FORMATTING -> view.onClearFormattingClick()
|
|
164
|
+
COMMAND_INDENT -> view.onIndentClick()
|
|
165
|
+
COMMAND_OUTDENT -> view.onOutdentClick()
|
|
166
|
+
COMMAND_ALIGN_LEFT -> view.onAlignLeftClick()
|
|
167
|
+
COMMAND_ALIGN_CENTER -> view.onAlignCenterClick()
|
|
168
|
+
COMMAND_ALIGN_RIGHT -> view.onAlignRightClick()
|
|
169
|
+
COMMAND_TOGGLE_CHECKLIST_ITEM -> view.onChecklistClick()
|
|
170
|
+
COMMAND_SET_TEXT -> {
|
|
171
|
+
val text = args?.getString(0) ?: ""
|
|
172
|
+
view.setTextContent(text, force = true)
|
|
173
|
+
}
|
|
174
|
+
COMMAND_SET_SELECTION -> {
|
|
175
|
+
val start = args?.getInt(0) ?: 0
|
|
176
|
+
val end = args?.getInt(1) ?: start
|
|
177
|
+
view.setSelectionRange(start, end)
|
|
178
|
+
}
|
|
179
|
+
COMMAND_SET_CONTENT -> {
|
|
180
|
+
val blocksArray = args?.getArray(0)
|
|
181
|
+
if (blocksArray != null) {
|
|
182
|
+
val blocksList = mutableListOf<Map<String, Any>>()
|
|
183
|
+
for (i in 0 until blocksArray.size()) {
|
|
184
|
+
val block = blocksArray.getMap(i) ?: continue
|
|
185
|
+
val blockMap = mutableMapOf<String, Any>()
|
|
186
|
+
blockMap["text"] = block.getString("text") ?: ""
|
|
187
|
+
blockMap["type"] = block.getString("type") ?: "paragraph"
|
|
188
|
+
val stylesList = mutableListOf<Map<String, Any>>()
|
|
189
|
+
val styles = block.getArray("styles")
|
|
190
|
+
if (styles != null) {
|
|
191
|
+
for (j in 0 until styles.size()) {
|
|
192
|
+
val style = styles.getMap(j) ?: continue
|
|
193
|
+
val styleMap = mutableMapOf<String, Any>()
|
|
194
|
+
val styleName = style.getString("style") ?: ""
|
|
195
|
+
styleMap["style"] = styleName
|
|
196
|
+
styleMap["start"] = style.getInt("start")
|
|
197
|
+
styleMap["end"] = style.getInt("end")
|
|
198
|
+
// Preserve url for link styles
|
|
199
|
+
if (styleName == "link" && style.hasKey("url")) {
|
|
200
|
+
styleMap["url"] = style.getString("url") ?: ""
|
|
201
|
+
}
|
|
202
|
+
stylesList.add(styleMap)
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
blockMap["styles"] = stylesList
|
|
206
|
+
blocksList.add(blockMap)
|
|
207
|
+
}
|
|
208
|
+
view.setContent(blocksList)
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
COMMAND_SET_MENTION_RANGES -> {
|
|
212
|
+
val rangesArray = args?.getArray(0)
|
|
213
|
+
if (rangesArray != null) {
|
|
214
|
+
val ranges = mutableListOf<Pair<Int, Int>>()
|
|
215
|
+
for (i in 0 until rangesArray.size()) {
|
|
216
|
+
val rangeMap = rangesArray.getMap(i) ?: continue
|
|
217
|
+
val start = rangeMap.getInt("start")
|
|
218
|
+
val end = rangeMap.getInt("end")
|
|
219
|
+
ranges.add(Pair(start, end))
|
|
220
|
+
}
|
|
221
|
+
view.setMentionRanges(ranges)
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
COMMAND_REMOVE_LINK -> {
|
|
225
|
+
val location = args?.getInt(0) ?: return
|
|
226
|
+
val length = args?.getInt(1) ?: return
|
|
227
|
+
view.removeLink(location, length)
|
|
228
|
+
}
|
|
229
|
+
COMMAND_UPDATE_LINK -> {
|
|
230
|
+
val location = args?.getInt(0) ?: return
|
|
231
|
+
val length = args?.getInt(1) ?: return
|
|
232
|
+
val newUrl = args?.getString(2) ?: return
|
|
233
|
+
val newText = args?.getString(3) ?: return
|
|
234
|
+
view.updateLink(location, length, newUrl, newText)
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
@ReactProp(name = "toolbarMode")
|
|
242
|
+
fun setToolbarMode(container: LinearLayout, mode: String?) {
|
|
243
|
+
val editor = getEditor(container) ?: return
|
|
244
|
+
val isInline = mode == "inline"
|
|
245
|
+
|
|
246
|
+
if (isInline) {
|
|
247
|
+
editor.setShowToolbar(false)
|
|
248
|
+
} else {
|
|
249
|
+
editor.setShowToolbar(true)
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
@ReactProp(name = "placeholder")
|
|
254
|
+
fun setPlaceholder(container: LinearLayout, placeholder: String?) {
|
|
255
|
+
try {
|
|
256
|
+
getEditor(container)?.setPlaceholderText(placeholder ?: "")
|
|
257
|
+
} catch (e: Exception) { e.printStackTrace() }
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
@ReactProp(name = "editable")
|
|
261
|
+
fun setEditable(container: LinearLayout, editable: Boolean) {
|
|
262
|
+
try {
|
|
263
|
+
getEditor(container)?.setEditable(editable)
|
|
264
|
+
} catch (e: Exception) { e.printStackTrace() }
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
@ReactProp(name = "maxHeight")
|
|
268
|
+
fun setMaxHeight(container: LinearLayout, maxHeight: Double) {
|
|
269
|
+
try {
|
|
270
|
+
getEditor(container)?.setMaxHeightValue(maxHeight.toInt())
|
|
271
|
+
} catch (e: Exception) { e.printStackTrace() }
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
@ReactProp(name = "numberOfLines")
|
|
275
|
+
fun setNumberOfLines(container: LinearLayout, numberOfLines: Int) {
|
|
276
|
+
try {
|
|
277
|
+
getEditor(container)?.setNumberOfLinesValue(numberOfLines)
|
|
278
|
+
} catch (e: Exception) { e.printStackTrace() }
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
@ReactProp(name = "showToolbar")
|
|
282
|
+
fun setShowToolbar(container: LinearLayout, showToolbar: Boolean) {
|
|
283
|
+
try {
|
|
284
|
+
showToolbarState[container.id] = showToolbar
|
|
285
|
+
val editor = getEditor(container) ?: return
|
|
286
|
+
editor.setShowToolbar(showToolbar)
|
|
287
|
+
} catch (e: Exception) { e.printStackTrace() }
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
@ReactProp(name = "toolbarOptions")
|
|
291
|
+
fun setToolbarOptions(container: LinearLayout, toolbarOptions: ReadableArray?) {
|
|
292
|
+
try {
|
|
293
|
+
val options = if (toolbarOptions != null) {
|
|
294
|
+
val list = mutableListOf<String>()
|
|
295
|
+
for (i in 0 until toolbarOptions.size()) {
|
|
296
|
+
toolbarOptions.getString(i)?.let { list.add(it) }
|
|
297
|
+
}
|
|
298
|
+
list
|
|
299
|
+
} else null
|
|
300
|
+
getEditor(container)?.setToolbarOptions(options)
|
|
301
|
+
} catch (e: Exception) { e.printStackTrace() }
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
@ReactProp(name = "variant")
|
|
305
|
+
fun setVariant(container: LinearLayout, variant: String?) {
|
|
306
|
+
try {
|
|
307
|
+
getEditor(container)?.setVariant(variant ?: "outlined")
|
|
308
|
+
} catch (e: Exception) { e.printStackTrace() }
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
@ReactProp(name = "initialContentJson")
|
|
312
|
+
fun setInitialContentJson(container: LinearLayout, initialContentJson: String?) {
|
|
313
|
+
if (initialContentJson.isNullOrEmpty()) return
|
|
314
|
+
try {
|
|
315
|
+
val editor = getEditor(container) ?: return
|
|
316
|
+
val json = org.json.JSONArray(initialContentJson)
|
|
317
|
+
val blocksList = mutableListOf<Map<String, Any>>()
|
|
318
|
+
for (i in 0 until json.length()) {
|
|
319
|
+
val block = json.getJSONObject(i)
|
|
320
|
+
val blockMap = mutableMapOf<String, Any>()
|
|
321
|
+
blockMap["text"] = block.optString("text", "")
|
|
322
|
+
blockMap["type"] = block.optString("type", "paragraph")
|
|
323
|
+
val stylesList = mutableListOf<Map<String, Any>>()
|
|
324
|
+
val styles = block.optJSONArray("styles")
|
|
325
|
+
if (styles != null) {
|
|
326
|
+
for (j in 0 until styles.length()) {
|
|
327
|
+
val style = styles.getJSONObject(j)
|
|
328
|
+
val styleMap = mutableMapOf<String, Any>()
|
|
329
|
+
val styleName = style.optString("style", "")
|
|
330
|
+
styleMap["style"] = styleName
|
|
331
|
+
styleMap["start"] = style.optInt("start", 0)
|
|
332
|
+
styleMap["end"] = style.optInt("end", 0)
|
|
333
|
+
// Preserve url for link styles
|
|
334
|
+
if (styleName == "link" && style.has("url")) {
|
|
335
|
+
styleMap["url"] = style.optString("url", "")
|
|
336
|
+
}
|
|
337
|
+
stylesList.add(styleMap)
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
blockMap["styles"] = stylesList
|
|
341
|
+
blocksList.add(blockMap)
|
|
342
|
+
}
|
|
343
|
+
editor.post { editor.setContent(blocksList) }
|
|
344
|
+
} catch (e: Exception) { e.printStackTrace() }
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
@ReactProp(name = "selection")
|
|
348
|
+
fun setSelection(container: LinearLayout, selection: ReadableMap?) {
|
|
349
|
+
try {
|
|
350
|
+
selection?.let {
|
|
351
|
+
val start = it.getInt("start")
|
|
352
|
+
val end = it.getInt("end")
|
|
353
|
+
getEditor(container)?.setSelectionRange(start, end)
|
|
354
|
+
}
|
|
355
|
+
} catch (e: Exception) { e.printStackTrace() }
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
@ReactProp(name = "textStyle")
|
|
359
|
+
fun setTextStyle(container: LinearLayout, textStyle: ReadableMap?) {
|
|
360
|
+
try {
|
|
361
|
+
textStyle?.let {
|
|
362
|
+
val fontSize = if (it.hasKey("fontSize")) it.getDouble("fontSize").toFloat() else null
|
|
363
|
+
val color = if (it.hasKey("color")) it.getString("color") else null
|
|
364
|
+
val fontFamily = if (it.hasKey("fontFamily")) it.getString("fontFamily") else null
|
|
365
|
+
getEditor(container)?.setTextStyle(fontSize, color, fontFamily)
|
|
366
|
+
}
|
|
367
|
+
} catch (e: Exception) { e.printStackTrace() }
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
@ReactProp(name = "placeholderTextColor")
|
|
371
|
+
fun setPlaceholderTextColor(container: LinearLayout, color: String?) {
|
|
372
|
+
try {
|
|
373
|
+
color?.let { getEditor(container)?.setPlaceholderTextColor(it) }
|
|
374
|
+
} catch (e: Exception) { e.printStackTrace() }
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
@ReactProp(name = "text")
|
|
378
|
+
fun setText(container: LinearLayout, text: String?) {
|
|
379
|
+
try {
|
|
380
|
+
if (text != null) {
|
|
381
|
+
getEditor(container)?.setTextContent(text)
|
|
382
|
+
}
|
|
383
|
+
} catch (e: Exception) { e.printStackTrace() }
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
@ReactProp(name = "codeBackgroundColor")
|
|
387
|
+
fun setCodeBackgroundColor(container: LinearLayout, color: String?) {
|
|
388
|
+
try {
|
|
389
|
+
val editor = getEditor(container) ?: return
|
|
390
|
+
editor.inlineCodeBackgroundColor = color?.let {
|
|
391
|
+
try { Color.parseColor(it) } catch (e: Exception) { null }
|
|
392
|
+
}
|
|
393
|
+
editor.invalidate()
|
|
394
|
+
} catch (e: Exception) { e.printStackTrace() }
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
@ReactProp(name = "codeBorderColor")
|
|
398
|
+
fun setCodeBorderColor(container: LinearLayout, color: String?) {
|
|
399
|
+
try {
|
|
400
|
+
val editor = getEditor(container) ?: return
|
|
401
|
+
editor.inlineCodeBorderColor = color?.let {
|
|
402
|
+
try { Color.parseColor(it) } catch (e: Exception) { null }
|
|
403
|
+
}
|
|
404
|
+
editor.invalidate()
|
|
405
|
+
} catch (e: Exception) { e.printStackTrace() }
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
@ReactProp(name = "codeTextColor")
|
|
409
|
+
fun setCodeTextColor(container: LinearLayout, color: String?) {
|
|
410
|
+
try {
|
|
411
|
+
val editor = getEditor(container) ?: return
|
|
412
|
+
editor.inlineCodeTextColor = color?.let {
|
|
413
|
+
try { Color.parseColor(it) } catch (e: Exception) { null }
|
|
414
|
+
}
|
|
415
|
+
} catch (e: Exception) { e.printStackTrace() }
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
@ReactProp(name = "codeFontSize")
|
|
419
|
+
fun setCodeFontSize(container: LinearLayout, size: Double) {
|
|
420
|
+
try {
|
|
421
|
+
val editor = getEditor(container) ?: return
|
|
422
|
+
editor.inlineCodeFontSize = if (size > 0) size.toFloat() else null
|
|
423
|
+
} catch (e: Exception) { e.printStackTrace() }
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
@ReactProp(name = "enterKeyBehavior")
|
|
427
|
+
fun setEnterKeyBehavior(container: LinearLayout, behavior: String?) {
|
|
428
|
+
try {
|
|
429
|
+
getEditor(container)?.enterKeyBehavior = behavior ?: "newLine"
|
|
430
|
+
} catch (e: Exception) { e.printStackTrace() }
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
@ReactProp(name = "showTextSelectionMenuItems", defaultBoolean = true)
|
|
434
|
+
fun setShowTextSelectionMenuItems(container: LinearLayout, show: Boolean) {
|
|
435
|
+
try {
|
|
436
|
+
getEditor(container)?.showTextSelectionMenuItems = show
|
|
437
|
+
} catch (e: Exception) { e.printStackTrace() }
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
|
|
441
|
+
return mutableMapOf(
|
|
442
|
+
"topContentChange" to mapOf("registrationName" to "onContentChange"),
|
|
443
|
+
"topSelectionChange" to mapOf("registrationName" to "onSelectionChange"),
|
|
444
|
+
"topEditorFocus" to mapOf("registrationName" to "onEditorFocus"),
|
|
445
|
+
"topEditorBlur" to mapOf("registrationName" to "onEditorBlur"),
|
|
446
|
+
"topSizeChange" to mapOf("registrationName" to "onSizeChange"),
|
|
447
|
+
"topActiveStylesChange" to mapOf("registrationName" to "onActiveStylesChange"),
|
|
448
|
+
"topLinkTap" to mapOf("registrationName" to "onLinkTap"),
|
|
449
|
+
"topSendRequest" to mapOf("registrationName" to "onSendRequest")
|
|
450
|
+
)
|
|
451
|
+
}
|
|
452
|
+
}
|