@@ -6,19 +6,19 @@ import com.facebook.react.bridge.ReadableMap
66import com.facebook.react.module.annotations.ReactModule
77import com.facebook.react.uimanager.SimpleViewManager
88import com.facebook.react.uimanager.ThemedReactContext
9- import com.facebook.react.uimanager.UIManagerHelper
109import com.facebook.react.uimanager.ViewManagerDelegate
1110import com.facebook.react.uimanager.annotations.ReactProp
1211import com.facebook.react.viewmanagers.EnrichedMarkdownTextManagerDelegate
1312import com.facebook.react.viewmanagers.EnrichedMarkdownTextManagerInterface
1413import com.facebook.yoga.YogaMeasureMode
15- import com.swmansion.enriched.markdown.events.ContextMenuItemPressEvent
16- import com.swmansion.enriched.markdown.events.LinkLongPressEvent
17- import com.swmansion.enriched.markdown.events.LinkPressEvent
18- import com.swmansion.enriched.markdown.events.TaskListItemPressEvent
19- import com.swmansion.enriched.markdown.parser.Md4cFlags
2014import com.swmansion.enriched.markdown.spoiler.SpoilerMode
21- import com.swmansion.enriched.markdown.utils.common.FeatureFlags
15+ import com.swmansion.enriched.markdown.utils.common.emitContextMenuItemPress
16+ import com.swmansion.enriched.markdown.utils.common.emitLinkLongPress
17+ import com.swmansion.enriched.markdown.utils.common.emitLinkPress
18+ import com.swmansion.enriched.markdown.utils.common.emitTaskListItemPress
19+ import com.swmansion.enriched.markdown.utils.common.markdownEventTypeConstants
20+ import com.swmansion.enriched.markdown.utils.common.parseContextMenuItems
21+ import com.swmansion.enriched.markdown.utils.common.parseMd4cFlags
2222import com.swmansion.enriched.markdown.utils.text.interaction.TaskListTapUtils
2323import com.swmansion.enriched.markdown.utils.text.interaction.TaskListToggleUtils
2424
@@ -47,28 +47,19 @@ class EnrichedMarkdownTextManager :
4747 view.clearActiveImageSpans()
4848 }
4949
50- override fun getExportedCustomDirectEventTypeConstants (): MutableMap <String , Any > {
51- val map = mutableMapOf<String , Any >()
52- map[LinkPressEvent .EVENT_NAME ] = mapOf (" registrationName" to LinkPressEvent .EVENT_NAME )
53- map[LinkLongPressEvent .EVENT_NAME ] = mapOf (" registrationName" to LinkLongPressEvent .EVENT_NAME )
54- map[TaskListItemPressEvent .EVENT_NAME ] =
55- mapOf (" registrationName" to TaskListItemPressEvent .EVENT_NAME )
56- map[ContextMenuItemPressEvent .EVENT_NAME ] =
57- mapOf (" registrationName" to ContextMenuItemPressEvent .EVENT_NAME )
58- return map
59- }
50+ override fun getExportedCustomDirectEventTypeConstants (): MutableMap <String , Any > = markdownEventTypeConstants()
6051
6152 @ReactProp(name = " markdown" )
6253 override fun setMarkdown (
6354 view : EnrichedMarkdownText ? ,
6455 markdown : String? ,
6556 ) {
6657 view?.setOnLinkPressCallback { url ->
67- emitOnLinkPress (view, url)
58+ emitLinkPress (view, url)
6859 }
6960
7061 view?.setOnLinkLongPressCallback { url ->
71- emitOnLinkLongPress (view, url)
62+ emitLinkLongPress (view, url)
7263 }
7364
7465 view?.setOnTaskListItemPressCallback { taskIndex, checked, itemText ->
@@ -79,15 +70,15 @@ class EnrichedMarkdownTextManager :
7970 styleConfig != null && TaskListTapUtils .updateTaskListItemCheckedState(view, taskIndex, newChecked, styleConfig)
8071
8172 if (optimizedSuccess) {
82- emitOnTaskListItemPress (view, taskIndex, newChecked, itemText)
73+ emitTaskListItemPress (view, taskIndex, newChecked, itemText)
8374 return @setOnTaskListItemPressCallback
8475 }
8576
8677 val currentMarkdown = view.currentMarkdown
8778 val updatedMarkdown = TaskListToggleUtils .toggleAtIndex(currentMarkdown, taskIndex, newChecked)
8879 view.setMarkdownContent(updatedMarkdown)
8980
90- emitOnTaskListItemPress (view, taskIndex, newChecked, itemText)
81+ emitTaskListItemPress (view, taskIndex, newChecked, itemText)
9182 }
9283
9384 view?.setMarkdownContent(markdown ? : " No markdown content" )
@@ -96,7 +87,7 @@ class EnrichedMarkdownTextManager :
9687 @ReactProp(name = " markdownStyle" )
9788 override fun setMarkdownStyle (
9889 view : EnrichedMarkdownText ? ,
99- style : com.facebook.react.bridge. ReadableMap ? ,
90+ style : ReadableMap ? ,
10091 ) {
10192 view?.setMarkdownStyle(style)
10293 }
@@ -114,12 +105,7 @@ class EnrichedMarkdownTextManager :
114105 view : EnrichedMarkdownText ? ,
115106 flags : ReadableMap ? ,
116107 ) {
117- val md4cFlags =
118- Md4cFlags (
119- underline = flags?.getBoolean(" underline" ) ? : false ,
120- latexMath = FeatureFlags .IS_MATH_ENABLED && (flags?.getBoolean(" latexMath" ) ? : true ),
121- )
122- view?.setMd4cFlags(md4cFlags)
108+ view?.setMd4cFlags(parseMd4cFlags(flags))
123109 }
124110
125111 @ReactProp(name = " allowFontScaling" , defaultBoolean = true )
@@ -151,8 +137,7 @@ class EnrichedMarkdownTextManager :
151137 view : EnrichedMarkdownText ? ,
152138 enableLinkPreview : Boolean ,
153139 ) {
154- // This prop is only used on iOS (to control the system link preview on long press).
155- // Required by the codegen interface but is a no-op on Android.
140+ // No-op on Android — only used on iOS
156141 }
157142
158143 @ReactProp(name = " streamingAnimation" , defaultBoolean = false )
@@ -177,8 +162,7 @@ class EnrichedMarkdownTextManager :
177162 value : ReadableArray ? ,
178163 ) {
179164 if (view == null ) return
180- val items = (0 until (value?.size() ? : 0 )).mapNotNull { value?.getMap(it)?.getString(" text" ) }
181- view.setContextMenuItems(items)
165+ view.setContextMenuItems(parseContextMenuItems(value))
182166 }
183167
184168 override fun setPadding (
@@ -192,57 +176,6 @@ class EnrichedMarkdownTextManager :
192176 view.setPadding(left, top, right, bottom)
193177 }
194178
195- private fun emitOnLinkPress (
196- view : EnrichedMarkdownText ,
197- url : String ,
198- ) {
199- val context = view.context as com.facebook.react.bridge.ReactContext
200- val surfaceId = UIManagerHelper .getSurfaceId(context)
201- val eventDispatcher = UIManagerHelper .getEventDispatcherForReactTag(context, view.id)
202- val event = LinkPressEvent (surfaceId, view.id, url)
203-
204- eventDispatcher?.dispatchEvent(event)
205- }
206-
207- private fun emitOnLinkLongPress (
208- view : EnrichedMarkdownText ,
209- url : String ,
210- ) {
211- val context = view.context as com.facebook.react.bridge.ReactContext
212- val surfaceId = UIManagerHelper .getSurfaceId(context)
213- val eventDispatcher = UIManagerHelper .getEventDispatcherForReactTag(context, view.id)
214- val event = LinkLongPressEvent (surfaceId, view.id, url)
215-
216- eventDispatcher?.dispatchEvent(event)
217- }
218-
219- private fun emitContextMenuItemPress (
220- view : EnrichedMarkdownText ,
221- itemText : String ,
222- selectedText : String ,
223- selectionStart : Int ,
224- selectionEnd : Int ,
225- ) {
226- val context = view.context as com.facebook.react.bridge.ReactContext
227- val surfaceId = UIManagerHelper .getSurfaceId(context)
228- val eventDispatcher = UIManagerHelper .getEventDispatcherForReactTag(context, view.id)
229- eventDispatcher?.dispatchEvent(ContextMenuItemPressEvent (surfaceId, view.id, itemText, selectedText, selectionStart, selectionEnd))
230- }
231-
232- private fun emitOnTaskListItemPress (
233- view : EnrichedMarkdownText ,
234- taskIndex : Int ,
235- checked : Boolean ,
236- itemText : String ,
237- ) {
238- val context = view.context as com.facebook.react.bridge.ReactContext
239- val surfaceId = UIManagerHelper .getSurfaceId(context)
240- val eventDispatcher = UIManagerHelper .getEventDispatcherForReactTag(context, view.id)
241- val event = TaskListItemPressEvent (surfaceId, view.id, taskIndex, checked, itemText)
242-
243- eventDispatcher?.dispatchEvent(event)
244- }
245-
246179 override fun measure (
247180 context : Context ,
248181 localData : ReadableMap ? ,
0 commit comments