From c7941a0a93895fa3edc636b3829f6221fc8535b5 Mon Sep 17 00:00:00 2001 From: Igor Furgala Date: Fri, 29 Aug 2025 09:15:31 +0200 Subject: [PATCH 1/8] chore: android basically working --- android/build.gradle | 10 +- android/gradle.properties | 10 +- android/src/main/AndroidManifest.xml | 2 +- .../EnrichedTextInputView.kt} | 34 ++--- .../EnrichedTextInputViewManager.kt} | 128 +++++++++--------- .../ReactNativeRichTextEditorPackage.kt | 6 +- ...ctNativeRichTextEditorViewLayoutManager.kt | 4 +- .../events/MentionHandler.kt | 6 +- .../events/OnChangeHtmlEvent.kt | 2 +- .../events/OnChangeSelectionEvent.kt | 2 +- .../events/OnChangeStateEvent.kt | 2 +- .../events/OnChangeTextEvent.kt | 2 +- .../events/OnInputBlurEvent.kt | 2 +- .../events/OnInputFocusEvent.kt | 2 +- .../events/OnLinkDetectedEvent.kt | 2 +- .../events/OnMentionDetectedEvent.kt | 2 +- .../events/OnMentionEvent.kt | 2 +- .../spans/EditorBlockQuoteSpan.kt | 6 +- .../spans/EditorBoldSpan.kt | 6 +- .../spans/EditorCodeBlockSpan.kt | 6 +- .../spans/EditorH1Span.kt | 6 +- .../spans/EditorH2Span.kt | 6 +- .../spans/EditorH3Span.kt | 6 +- .../spans/EditorImageSpan.kt | 6 +- .../spans/EditorInlineCodeSpan.kt | 6 +- .../spans/EditorItalicSpan.kt | 6 +- .../spans/EditorLinkSpan.kt | 6 +- .../spans/EditorMentionSpan.kt | 6 +- .../spans/EditorOrderedListSpan.kt | 6 +- .../spans/EditorSpans.kt | 2 +- .../enriched/spans/EditorStrikeThroughSpan.kt | 9 ++ .../enriched/spans/EditorUnderlineSpan.kt | 9 ++ .../spans/EditorUnorderedListSpan.kt | 6 +- .../spans/interfaces/EditorBlockSpan.kt | 2 +- .../spans/interfaces/EditorHeadingSpan.kt | 4 + .../spans/interfaces/EditorInlineSpan.kt | 4 + .../spans/interfaces/EditorParagraphSpan.kt | 2 +- .../enriched/spans/interfaces/EditorSpan.kt | 4 + .../interfaces/EditorZeroWidthSpaceSpan.kt | 2 +- .../styles/InlineStyles.kt | 10 +- .../styles/ListStyles.kt | 18 +-- .../styles/ParagraphStyles.kt | 12 +- .../styles/ParametrizedStyles.kt | 16 +-- .../styles/RichTextStyle.kt | 10 +- .../utils/EditorParser.java | 42 +++--- .../utils/EditorSelection.kt | 18 +-- .../utils/EditorSpanSpate.kt | 10 +- .../utils/Utils.kt | 6 +- .../watchers/EditorSpanWatcher.kt | 18 +-- .../watchers/EditorTextWatcher.kt | 8 +- .../spans/EditorStrikeThroughSpan.kt | 9 -- .../spans/EditorUnderlineSpan.kt | 9 -- .../spans/interfaces/EditorHeadingSpan.kt | 4 - .../spans/interfaces/EditorInlineSpan.kt | 4 - .../spans/interfaces/EditorSpan.kt | 4 - android/src/main/new_arch/CMakeLists.txt | 2 +- ...ec.cpp => RNEnrichedTextInputViewSpec.cpp} | 4 +- ...ewSpec.h => RNEnrichedTextInputViewSpec.h} | 4 +- .../EnrichedTextInputComponentDescriptor.h | 35 +++++ .../EnrichedTextInputMeasurementManager.cpp} | 8 +- .../EnrichedTextInputMeasurementManager.h} | 8 +- .../EnrichedTextInputShadowNode.cpp} | 12 +- .../EnrichedTextInputShadowNode.h} | 30 ++-- .../EnrichedTextInputState.cpp | 9 ++ .../EnrichedTextInputState.h} | 6 +- ...iveRichTextEditorViewComponentDescriptor.h | 35 ----- .../ReactNativeRichTextEditorViewState.cpp | 9 -- example/android/app/build.gradle | 4 +- .../example/MainActivity.kt | 4 +- .../example/MainApplication.kt | 2 +- .../app/src/main/res/values/strings.xml | 2 +- example/android/settings.gradle | 2 +- example/app.json | 4 +- example/package.json | 2 +- example/src/App.tsx | 16 +-- example/src/components/LinkModal.tsx | 2 +- example/src/components/Toolbar.tsx | 6 +- package.json | 8 +- react-native.config.js | 4 +- ...ichTextInput.tsx => EnrichedTextInput.tsx} | 32 ++--- ...ts => EnrichedTextInputNativeComponent.ts} | 13 +- src/index.tsx | 4 +- ...RichTextStyle.ts => normalizeHtmlStyle.ts} | 34 +++-- tsconfig.json | 2 +- yarn.lock | 108 +++++++-------- 85 files changed, 468 insertions(+), 475 deletions(-) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor/ReactNativeRichTextEditorView.kt => enriched/EnrichedTextInputView.kt} (93%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor/ReactNativeRichTextEditorViewManager.kt => enriched/EnrichedTextInputViewManager.kt} (54%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/ReactNativeRichTextEditorPackage.kt (76%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/ReactNativeRichTextEditorViewLayoutManager.kt (95%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/events/MentionHandler.kt (81%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/events/OnChangeHtmlEvent.kt (91%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/events/OnChangeSelectionEvent.kt (92%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/events/OnChangeStateEvent.kt (89%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/events/OnChangeTextEvent.kt (92%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/events/OnInputBlurEvent.kt (90%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/events/OnInputFocusEvent.kt (90%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/events/OnLinkDetectedEvent.kt (93%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/events/OnMentionDetectedEvent.kt (93%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/events/OnMentionEvent.kt (92%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/spans/EditorBlockQuoteSpan.kt (86%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/spans/EditorBoldSpan.kt (51%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/spans/EditorCodeBlockSpan.kt (83%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/spans/EditorH1Span.kt (67%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/spans/EditorH2Span.kt (68%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/spans/EditorH3Span.kt (68%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/spans/EditorImageSpan.kt (85%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/spans/EditorInlineCodeSpan.kt (70%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/spans/EditorItalicSpan.kt (51%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/spans/EditorLinkSpan.kt (76%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/spans/EditorMentionSpan.kt (83%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/spans/EditorOrderedListSpan.kt (90%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/spans/EditorSpans.kt (98%) create mode 100644 android/src/main/java/com/swmansion/enriched/spans/EditorStrikeThroughSpan.kt create mode 100644 android/src/main/java/com/swmansion/enriched/spans/EditorUnderlineSpan.kt rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/spans/EditorUnorderedListSpan.kt (86%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/spans/interfaces/EditorBlockSpan.kt (51%) create mode 100644 android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorHeadingSpan.kt create mode 100644 android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorInlineSpan.kt rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/spans/interfaces/EditorParagraphSpan.kt (53%) create mode 100644 android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorSpan.kt rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/spans/interfaces/EditorZeroWidthSpaceSpan.kt (69%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/styles/InlineStyles.kt (92%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/styles/ListStyles.kt (90%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/styles/ParagraphStyles.kt (93%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/styles/ParametrizedStyles.kt (92%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/styles/RichTextStyle.kt (95%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/utils/EditorParser.java (94%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/utils/EditorSelection.kt (93%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/utils/EditorSpanSpate.kt (94%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/utils/Utils.kt (92%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/watchers/EditorSpanWatcher.kt (76%) rename android/src/main/java/com/swmansion/{reactnativerichtexteditor => enriched}/watchers/EditorTextWatcher.kt (83%) delete mode 100644 android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorStrikeThroughSpan.kt delete mode 100644 android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorUnderlineSpan.kt delete mode 100644 android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/interfaces/EditorHeadingSpan.kt delete mode 100644 android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/interfaces/EditorInlineSpan.kt delete mode 100644 android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/interfaces/EditorSpan.kt rename android/src/main/new_arch/{RNReactNativeRichTextEditorViewSpec.cpp => RNEnrichedTextInputViewSpec.cpp} (64%) rename android/src/main/new_arch/{RNReactNativeRichTextEditorViewSpec.h => RNEnrichedTextInputViewSpec.h} (63%) create mode 100644 android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputComponentDescriptor.h rename android/src/main/new_arch/react/renderer/components/{RNReactNativeRichTextEditorViewSpec/RichTextEditorMeasurementManager.cpp => RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.cpp} (85%) rename android/src/main/new_arch/react/renderer/components/{RNReactNativeRichTextEditorViewSpec/RichTextEditorMeasurementManager.h => RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.h} (69%) rename android/src/main/new_arch/react/renderer/components/{RNReactNativeRichTextEditorViewSpec/ReactNativeRichTextEditorShadowNode.cpp => RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.cpp} (68%) rename android/src/main/new_arch/react/renderer/components/{RNReactNativeRichTextEditorViewSpec/ReactNativeRichTextEditorShadowNode.h => RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.h} (53%) create mode 100644 android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.cpp rename android/src/main/new_arch/react/renderer/components/{RNReactNativeRichTextEditorViewSpec/ReactNativeRichTextEditorViewState.h => RNEnrichedTextInputViewSpec/EnrichedTextInputState.h} (71%) delete mode 100644 android/src/main/new_arch/react/renderer/components/RNReactNativeRichTextEditorViewSpec/ReactNativeRichTextEditorViewComponentDescriptor.h delete mode 100644 android/src/main/new_arch/react/renderer/components/RNReactNativeRichTextEditorViewSpec/ReactNativeRichTextEditorViewState.cpp rename example/android/app/src/main/java/swmansion/{reactnativerichtexteditor => enriched}/example/MainActivity.kt (85%) rename example/android/app/src/main/java/swmansion/{reactnativerichtexteditor => enriched}/example/MainApplication.kt (96%) rename src/{RichTextInput.tsx => EnrichedTextInput.tsx} (92%) rename src/{ReactNativeRichTextEditorViewNativeComponent.ts => EnrichedTextInputNativeComponent.ts} (96%) rename src/{normalizeRichTextStyle.ts => normalizeHtmlStyle.ts} (82%) diff --git a/android/build.gradle b/android/build.gradle index eef02f3bb..eae1bd08e 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,6 +1,6 @@ buildscript { ext.getExtOrDefault = {name -> - return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['ReactNativeRichTextEditor_' + name] + return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['EnrichedTextInput_' + name] } repositories { @@ -22,7 +22,7 @@ apply plugin: "kotlin-android" apply plugin: "com.facebook.react" def getExtOrIntegerDefault(name) { - return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["ReactNativeRichTextEditor_" + name]).toInteger() + return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["EnrichedTextInput_" + name]).toInteger() } def supportsNamespace() { @@ -36,7 +36,7 @@ def supportsNamespace() { android { if (supportsNamespace()) { - namespace "com.swmansion.reactnativerichtexteditor" + namespace "com.swmansion.enriched" sourceSets { main { @@ -96,6 +96,6 @@ dependencies { react { jsRootDir = file("../src/") - libraryName = "ReactNativeRichTextEditorView" - codegenJavaPackageName = "com.swmansion.reactnativerichtexteditor" + libraryName = "EnrichedTextInputView" + codegenJavaPackageName = "com.swmansion.enriched" } diff --git a/android/gradle.properties b/android/gradle.properties index fb3770121..edb83f5c4 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,5 +1,5 @@ -ReactNativeRichTextEditor_kotlinVersion=2.0.21 -ReactNativeRichTextEditor_minSdkVersion=24 -ReactNativeRichTextEditor_targetSdkVersion=34 -ReactNativeRichTextEditor_compileSdkVersion=35 -ReactNativeRichTextEditor_ndkVersion=27.1.12297006 +EnrichedTextInput_kotlinVersion=2.0.21 +EnrichedTextInput_minSdkVersion=24 +EnrichedTextInput_targetSdkVersion=34 +EnrichedTextInput_compileSdkVersion=35 +EnrichedTextInput__ndkVersion=27.1.12297006 diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index d2c28b086..cbd1d3718 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,3 +1,3 @@ + package="com.swmansion.enriched"> diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/ReactNativeRichTextEditorView.kt b/android/src/main/java/com/swmansion/enriched/EnrichedTextInputView.kt similarity index 93% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/ReactNativeRichTextEditorView.kt rename to android/src/main/java/com/swmansion/enriched/EnrichedTextInputView.kt index 9134b1904..f1601c472 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/ReactNativeRichTextEditorView.kt +++ b/android/src/main/java/com/swmansion/enriched/EnrichedTextInputView.kt @@ -1,4 +1,4 @@ -package com.swmansion.reactnativerichtexteditor +package com.swmansion.enriched import android.content.ClipData import android.content.ClipboardManager @@ -25,25 +25,25 @@ import com.facebook.react.uimanager.UIManagerHelper import com.facebook.react.views.text.ReactTypefaceUtils.applyStyles import com.facebook.react.views.text.ReactTypefaceUtils.parseFontStyle import com.facebook.react.views.text.ReactTypefaceUtils.parseFontWeight -import com.swmansion.reactnativerichtexteditor.events.MentionHandler -import com.swmansion.reactnativerichtexteditor.events.OnInputBlurEvent -import com.swmansion.reactnativerichtexteditor.events.OnInputFocusEvent -import com.swmansion.reactnativerichtexteditor.spans.EditorSpans -import com.swmansion.reactnativerichtexteditor.styles.InlineStyles -import com.swmansion.reactnativerichtexteditor.styles.ListStyles -import com.swmansion.reactnativerichtexteditor.styles.ParagraphStyles -import com.swmansion.reactnativerichtexteditor.styles.ParametrizedStyles -import com.swmansion.reactnativerichtexteditor.styles.RichTextStyle -import com.swmansion.reactnativerichtexteditor.utils.EditorParser -import com.swmansion.reactnativerichtexteditor.utils.EditorSelection -import com.swmansion.reactnativerichtexteditor.utils.EditorSpanState -import com.swmansion.reactnativerichtexteditor.utils.mergeSpannables -import com.swmansion.reactnativerichtexteditor.watchers.EditorSpanWatcher -import com.swmansion.reactnativerichtexteditor.watchers.EditorTextWatcher +import com.swmansion.enriched.events.MentionHandler +import com.swmansion.enriched.events.OnInputBlurEvent +import com.swmansion.enriched.events.OnInputFocusEvent +import com.swmansion.enriched.spans.EditorSpans +import com.swmansion.enriched.styles.InlineStyles +import com.swmansion.enriched.styles.ListStyles +import com.swmansion.enriched.styles.ParagraphStyles +import com.swmansion.enriched.styles.ParametrizedStyles +import com.swmansion.enriched.styles.RichTextStyle +import com.swmansion.enriched.utils.EditorParser +import com.swmansion.enriched.utils.EditorSelection +import com.swmansion.enriched.utils.EditorSpanState +import com.swmansion.enriched.utils.mergeSpannables +import com.swmansion.enriched.watchers.EditorSpanWatcher +import com.swmansion.enriched.watchers.EditorTextWatcher import kotlin.math.ceil -class ReactNativeRichTextEditorView : AppCompatEditText { +class EnrichedTextInputView : AppCompatEditText { var stateWrapper: StateWrapper? = null val selection: EditorSelection? = EditorSelection(this) val spanState: EditorSpanState? = EditorSpanState(this) diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/ReactNativeRichTextEditorViewManager.kt b/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewManager.kt similarity index 54% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/ReactNativeRichTextEditorViewManager.kt rename to android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewManager.kt index 311eb4627..41fcef382 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/ReactNativeRichTextEditorViewManager.kt +++ b/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewManager.kt @@ -1,4 +1,4 @@ -package com.swmansion.reactnativerichtexteditor +package com.swmansion.enriched import android.content.Context import com.facebook.react.bridge.ReadableArray @@ -12,34 +12,34 @@ import com.facebook.react.uimanager.ViewDefaults import com.facebook.react.uimanager.ViewManagerDelegate import com.facebook.react.uimanager.ViewProps import com.facebook.react.uimanager.annotations.ReactProp -import com.facebook.react.viewmanagers.ReactNativeRichTextEditorViewManagerInterface -import com.facebook.react.viewmanagers.ReactNativeRichTextEditorViewManagerDelegate +import com.facebook.react.viewmanagers.EnrichedTextInputViewManagerDelegate +import com.facebook.react.viewmanagers.EnrichedTextInputViewManagerInterface import com.facebook.yoga.YogaMeasureMode import com.facebook.yoga.YogaMeasureOutput -import com.swmansion.reactnativerichtexteditor.events.OnInputBlurEvent -import com.swmansion.reactnativerichtexteditor.events.OnChangeHtmlEvent -import com.swmansion.reactnativerichtexteditor.events.OnChangeSelectionEvent -import com.swmansion.reactnativerichtexteditor.events.OnChangeStateEvent -import com.swmansion.reactnativerichtexteditor.events.OnChangeTextEvent -import com.swmansion.reactnativerichtexteditor.events.OnInputFocusEvent -import com.swmansion.reactnativerichtexteditor.events.OnLinkDetectedEvent -import com.swmansion.reactnativerichtexteditor.events.OnMentionDetectedEvent -import com.swmansion.reactnativerichtexteditor.events.OnMentionEvent -import com.swmansion.reactnativerichtexteditor.spans.EditorSpans -import com.swmansion.reactnativerichtexteditor.styles.RichTextStyle -import com.swmansion.reactnativerichtexteditor.utils.jsonStringToStringMap - -@ReactModule(name = ReactNativeRichTextEditorViewManager.NAME) -class ReactNativeRichTextEditorViewManager : SimpleViewManager(), - ReactNativeRichTextEditorViewManagerInterface { - private val mDelegate: ViewManagerDelegate - private var view: ReactNativeRichTextEditorView? = null +import com.swmansion.enriched.events.OnInputBlurEvent +import com.swmansion.enriched.events.OnChangeHtmlEvent +import com.swmansion.enriched.events.OnChangeSelectionEvent +import com.swmansion.enriched.events.OnChangeStateEvent +import com.swmansion.enriched.events.OnChangeTextEvent +import com.swmansion.enriched.events.OnInputFocusEvent +import com.swmansion.enriched.events.OnLinkDetectedEvent +import com.swmansion.enriched.events.OnMentionDetectedEvent +import com.swmansion.enriched.events.OnMentionEvent +import com.swmansion.enriched.spans.EditorSpans +import com.swmansion.enriched.styles.RichTextStyle +import com.swmansion.enriched.utils.jsonStringToStringMap + +@ReactModule(name = EnrichedTextInputViewManager.NAME) +class EnrichedTextInputViewManager : SimpleViewManager(), + EnrichedTextInputViewManagerInterface { + private val mDelegate: ViewManagerDelegate + private var view: EnrichedTextInputView? = null init { - mDelegate = ReactNativeRichTextEditorViewManagerDelegate(this) + mDelegate = EnrichedTextInputViewManagerDelegate(this) } - override fun getDelegate(): ViewManagerDelegate? { + override fun getDelegate(): ViewManagerDelegate? { return mDelegate } @@ -47,15 +47,15 @@ class ReactNativeRichTextEditorViewManager : SimpleViewManager() @@ -128,42 +128,42 @@ class ReactNativeRichTextEditorViewManager : SimpleViewManager> { val viewManagers: MutableList> = ArrayList() - viewManagers.add(ReactNativeRichTextEditorViewManager()) + viewManagers.add(EnrichedTextInputViewManager()) return viewManagers } diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/ReactNativeRichTextEditorViewLayoutManager.kt b/android/src/main/java/com/swmansion/enriched/ReactNativeRichTextEditorViewLayoutManager.kt similarity index 95% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/ReactNativeRichTextEditorViewLayoutManager.kt rename to android/src/main/java/com/swmansion/enriched/ReactNativeRichTextEditorViewLayoutManager.kt index 8c7bccde8..53768959f 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/ReactNativeRichTextEditorViewLayoutManager.kt +++ b/android/src/main/java/com/swmansion/enriched/ReactNativeRichTextEditorViewLayoutManager.kt @@ -1,11 +1,11 @@ -package com.swmansion.reactnativerichtexteditor +package com.swmansion.enriched import android.text.Editable import android.text.StaticLayout import com.facebook.react.bridge.Arguments import com.facebook.react.uimanager.PixelUtil -class ReactNativeRichTextEditorViewLayoutManager(private val editorView: ReactNativeRichTextEditorView) { +class ReactNativeRichTextEditorViewLayoutManager(private val editorView: EnrichedTextInputView) { private var cachedSize: Pair = Pair(0f, 0f) private var cachedYogaWidth: Float = 0f private var forceHeightRecalculationCounter: Int = 0 diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/events/MentionHandler.kt b/android/src/main/java/com/swmansion/enriched/events/MentionHandler.kt similarity index 81% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/events/MentionHandler.kt rename to android/src/main/java/com/swmansion/enriched/events/MentionHandler.kt index 480541bc7..53da0a5b8 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/events/MentionHandler.kt +++ b/android/src/main/java/com/swmansion/enriched/events/MentionHandler.kt @@ -1,10 +1,10 @@ -package com.swmansion.reactnativerichtexteditor.events +package com.swmansion.enriched.events import com.facebook.react.bridge.ReactContext import com.facebook.react.uimanager.UIManagerHelper -import com.swmansion.reactnativerichtexteditor.ReactNativeRichTextEditorView +import com.swmansion.enriched.EnrichedTextInputView -class MentionHandler(private val editorView: ReactNativeRichTextEditorView) { +class MentionHandler(private val editorView: EnrichedTextInputView) { private var previousText: String? = null private var previousIndicator: String? = null diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnChangeHtmlEvent.kt b/android/src/main/java/com/swmansion/enriched/events/OnChangeHtmlEvent.kt similarity index 91% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnChangeHtmlEvent.kt rename to android/src/main/java/com/swmansion/enriched/events/OnChangeHtmlEvent.kt index 0fbe715e6..d55d65ce0 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnChangeHtmlEvent.kt +++ b/android/src/main/java/com/swmansion/enriched/events/OnChangeHtmlEvent.kt @@ -1,4 +1,4 @@ -package com.swmansion.reactnativerichtexteditor.events +package com.swmansion.enriched.events import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.WritableMap diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnChangeSelectionEvent.kt b/android/src/main/java/com/swmansion/enriched/events/OnChangeSelectionEvent.kt similarity index 92% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnChangeSelectionEvent.kt rename to android/src/main/java/com/swmansion/enriched/events/OnChangeSelectionEvent.kt index 9248f1dc7..8fe418996 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnChangeSelectionEvent.kt +++ b/android/src/main/java/com/swmansion/enriched/events/OnChangeSelectionEvent.kt @@ -1,4 +1,4 @@ -package com.swmansion.reactnativerichtexteditor.events +package com.swmansion.enriched.events import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.WritableMap diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnChangeStateEvent.kt b/android/src/main/java/com/swmansion/enriched/events/OnChangeStateEvent.kt similarity index 89% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnChangeStateEvent.kt rename to android/src/main/java/com/swmansion/enriched/events/OnChangeStateEvent.kt index a462dd7e6..e70d66a77 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnChangeStateEvent.kt +++ b/android/src/main/java/com/swmansion/enriched/events/OnChangeStateEvent.kt @@ -1,4 +1,4 @@ -package com.swmansion.reactnativerichtexteditor.events +package com.swmansion.enriched.events import com.facebook.react.bridge.WritableMap import com.facebook.react.uimanager.events.Event diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnChangeTextEvent.kt b/android/src/main/java/com/swmansion/enriched/events/OnChangeTextEvent.kt similarity index 92% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnChangeTextEvent.kt rename to android/src/main/java/com/swmansion/enriched/events/OnChangeTextEvent.kt index e46121434..13e4cdea9 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnChangeTextEvent.kt +++ b/android/src/main/java/com/swmansion/enriched/events/OnChangeTextEvent.kt @@ -1,4 +1,4 @@ -package com.swmansion.reactnativerichtexteditor.events +package com.swmansion.enriched.events import android.text.Editable import com.facebook.react.bridge.Arguments diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnInputBlurEvent.kt b/android/src/main/java/com/swmansion/enriched/events/OnInputBlurEvent.kt similarity index 90% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnInputBlurEvent.kt rename to android/src/main/java/com/swmansion/enriched/events/OnInputBlurEvent.kt index f39b6a515..adf328a23 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnInputBlurEvent.kt +++ b/android/src/main/java/com/swmansion/enriched/events/OnInputBlurEvent.kt @@ -1,4 +1,4 @@ -package com.swmansion.reactnativerichtexteditor.events +package com.swmansion.enriched.events import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.WritableMap diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnInputFocusEvent.kt b/android/src/main/java/com/swmansion/enriched/events/OnInputFocusEvent.kt similarity index 90% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnInputFocusEvent.kt rename to android/src/main/java/com/swmansion/enriched/events/OnInputFocusEvent.kt index 41fde8d30..1fe16b75d 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnInputFocusEvent.kt +++ b/android/src/main/java/com/swmansion/enriched/events/OnInputFocusEvent.kt @@ -1,4 +1,4 @@ -package com.swmansion.reactnativerichtexteditor.events +package com.swmansion.enriched.events import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.WritableMap diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnLinkDetectedEvent.kt b/android/src/main/java/com/swmansion/enriched/events/OnLinkDetectedEvent.kt similarity index 93% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnLinkDetectedEvent.kt rename to android/src/main/java/com/swmansion/enriched/events/OnLinkDetectedEvent.kt index 1f2962acf..ee90f9e25 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnLinkDetectedEvent.kt +++ b/android/src/main/java/com/swmansion/enriched/events/OnLinkDetectedEvent.kt @@ -1,4 +1,4 @@ -package com.swmansion.reactnativerichtexteditor.events +package com.swmansion.enriched.events import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.WritableMap diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnMentionDetectedEvent.kt b/android/src/main/java/com/swmansion/enriched/events/OnMentionDetectedEvent.kt similarity index 93% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnMentionDetectedEvent.kt rename to android/src/main/java/com/swmansion/enriched/events/OnMentionDetectedEvent.kt index 9bbed75ab..51c684614 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnMentionDetectedEvent.kt +++ b/android/src/main/java/com/swmansion/enriched/events/OnMentionDetectedEvent.kt @@ -1,4 +1,4 @@ -package com.swmansion.reactnativerichtexteditor.events +package com.swmansion.enriched.events import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.WritableMap diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnMentionEvent.kt b/android/src/main/java/com/swmansion/enriched/events/OnMentionEvent.kt similarity index 92% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnMentionEvent.kt rename to android/src/main/java/com/swmansion/enriched/events/OnMentionEvent.kt index ccb65db02..1849b09df 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/events/OnMentionEvent.kt +++ b/android/src/main/java/com/swmansion/enriched/events/OnMentionEvent.kt @@ -1,4 +1,4 @@ -package com.swmansion.reactnativerichtexteditor.events +package com.swmansion.enriched.events import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.WritableMap diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorBlockQuoteSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EditorBlockQuoteSpan.kt similarity index 86% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorBlockQuoteSpan.kt rename to android/src/main/java/com/swmansion/enriched/spans/EditorBlockQuoteSpan.kt index a78ce73de..5f26334e5 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorBlockQuoteSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EditorBlockQuoteSpan.kt @@ -1,4 +1,4 @@ -package com.swmansion.reactnativerichtexteditor.spans +package com.swmansion.enriched.spans import android.graphics.Canvas import android.graphics.Paint @@ -6,8 +6,8 @@ import android.text.Layout import android.text.TextPaint import android.text.style.CharacterStyle import android.text.style.LeadingMarginSpan -import com.swmansion.reactnativerichtexteditor.spans.interfaces.EditorBlockSpan -import com.swmansion.reactnativerichtexteditor.styles.RichTextStyle +import com.swmansion.enriched.spans.interfaces.EditorBlockSpan +import com.swmansion.enriched.styles.RichTextStyle // https://android.googlesource.com/platform/frameworks/base/+/refs/heads/main/core/java/android/text/style/QuoteSpan.java class EditorBlockQuoteSpan(private val richTextStyle: RichTextStyle) : CharacterStyle(), LeadingMarginSpan, EditorBlockSpan { diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorBoldSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EditorBoldSpan.kt similarity index 51% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorBoldSpan.kt rename to android/src/main/java/com/swmansion/enriched/spans/EditorBoldSpan.kt index d0a46910e..f16e67663 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorBoldSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EditorBoldSpan.kt @@ -1,9 +1,9 @@ -package com.swmansion.reactnativerichtexteditor.spans +package com.swmansion.enriched.spans import android.graphics.Typeface import android.text.style.StyleSpan -import com.swmansion.reactnativerichtexteditor.spans.interfaces.EditorInlineSpan -import com.swmansion.reactnativerichtexteditor.styles.RichTextStyle +import com.swmansion.enriched.spans.interfaces.EditorInlineSpan +import com.swmansion.enriched.styles.RichTextStyle @Suppress("UNUSED_PARAMETER") class EditorBoldSpan(private val richTextStyle: RichTextStyle) : StyleSpan(Typeface.BOLD), EditorInlineSpan { diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorCodeBlockSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EditorCodeBlockSpan.kt similarity index 83% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorCodeBlockSpan.kt rename to android/src/main/java/com/swmansion/enriched/spans/EditorCodeBlockSpan.kt index d85b3d1dd..bf55eda5d 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorCodeBlockSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EditorCodeBlockSpan.kt @@ -1,4 +1,4 @@ -package com.swmansion.reactnativerichtexteditor.spans +package com.swmansion.enriched.spans import android.graphics.Canvas import android.graphics.Paint @@ -7,8 +7,8 @@ import android.graphics.Typeface import android.text.TextPaint import android.text.style.CharacterStyle import android.text.style.LineBackgroundSpan -import com.swmansion.reactnativerichtexteditor.spans.interfaces.EditorBlockSpan -import com.swmansion.reactnativerichtexteditor.styles.RichTextStyle +import com.swmansion.enriched.spans.interfaces.EditorBlockSpan +import com.swmansion.enriched.styles.RichTextStyle class EditorCodeBlockSpan(private val richTextStyle: RichTextStyle) : CharacterStyle(), LineBackgroundSpan, EditorBlockSpan { override fun updateDrawState(paint: TextPaint?) { diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorH1Span.kt b/android/src/main/java/com/swmansion/enriched/spans/EditorH1Span.kt similarity index 67% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorH1Span.kt rename to android/src/main/java/com/swmansion/enriched/spans/EditorH1Span.kt index 67501e777..3810bc397 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorH1Span.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EditorH1Span.kt @@ -1,10 +1,10 @@ -package com.swmansion.reactnativerichtexteditor.spans +package com.swmansion.enriched.spans import android.graphics.Typeface import android.text.TextPaint import android.text.style.AbsoluteSizeSpan -import com.swmansion.reactnativerichtexteditor.spans.interfaces.EditorHeadingSpan -import com.swmansion.reactnativerichtexteditor.styles.RichTextStyle +import com.swmansion.enriched.spans.interfaces.EditorHeadingSpan +import com.swmansion.enriched.styles.RichTextStyle class EditorH1Span(private val style: RichTextStyle) : AbsoluteSizeSpan(style.h1FontSize), EditorHeadingSpan { override fun updateDrawState(tp: TextPaint) { diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorH2Span.kt b/android/src/main/java/com/swmansion/enriched/spans/EditorH2Span.kt similarity index 68% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorH2Span.kt rename to android/src/main/java/com/swmansion/enriched/spans/EditorH2Span.kt index bb7a6382e..e015aef5c 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorH2Span.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EditorH2Span.kt @@ -1,10 +1,10 @@ -package com.swmansion.reactnativerichtexteditor.spans +package com.swmansion.enriched.spans import android.graphics.Typeface import android.text.TextPaint import android.text.style.AbsoluteSizeSpan -import com.swmansion.reactnativerichtexteditor.spans.interfaces.EditorHeadingSpan -import com.swmansion.reactnativerichtexteditor.styles.RichTextStyle +import com.swmansion.enriched.spans.interfaces.EditorHeadingSpan +import com.swmansion.enriched.styles.RichTextStyle class EditorH2Span(private val richTextStyle: RichTextStyle) : AbsoluteSizeSpan(richTextStyle.h2FontSize), EditorHeadingSpan { override fun updateDrawState(tp: TextPaint) { diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorH3Span.kt b/android/src/main/java/com/swmansion/enriched/spans/EditorH3Span.kt similarity index 68% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorH3Span.kt rename to android/src/main/java/com/swmansion/enriched/spans/EditorH3Span.kt index 40544262d..99351553e 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorH3Span.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EditorH3Span.kt @@ -1,10 +1,10 @@ -package com.swmansion.reactnativerichtexteditor.spans +package com.swmansion.enriched.spans import android.graphics.Typeface import android.text.TextPaint import android.text.style.AbsoluteSizeSpan -import com.swmansion.reactnativerichtexteditor.spans.interfaces.EditorHeadingSpan -import com.swmansion.reactnativerichtexteditor.styles.RichTextStyle +import com.swmansion.enriched.spans.interfaces.EditorHeadingSpan +import com.swmansion.enriched.styles.RichTextStyle class EditorH3Span(private val richTextStyle: RichTextStyle) : AbsoluteSizeSpan(richTextStyle.h3FontSize), EditorHeadingSpan { override fun updateDrawState(tp: TextPaint) { diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorImageSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EditorImageSpan.kt similarity index 85% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorImageSpan.kt rename to android/src/main/java/com/swmansion/enriched/spans/EditorImageSpan.kt index b84d03584..265411323 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorImageSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EditorImageSpan.kt @@ -1,4 +1,4 @@ -package com.swmansion.reactnativerichtexteditor.spans +package com.swmansion.enriched.spans import android.content.Context import android.graphics.Canvas @@ -7,8 +7,8 @@ import android.graphics.drawable.Drawable import android.net.Uri import android.text.style.ImageSpan import androidx.core.graphics.withSave -import com.swmansion.reactnativerichtexteditor.spans.interfaces.EditorInlineSpan -import com.swmansion.reactnativerichtexteditor.styles.RichTextStyle +import com.swmansion.enriched.spans.interfaces.EditorInlineSpan +import com.swmansion.enriched.styles.RichTextStyle class EditorImageSpan : ImageSpan, EditorInlineSpan { private var richTextStyle: RichTextStyle? = null diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorInlineCodeSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EditorInlineCodeSpan.kt similarity index 70% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorInlineCodeSpan.kt rename to android/src/main/java/com/swmansion/enriched/spans/EditorInlineCodeSpan.kt index 79166feb4..2ecf09390 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorInlineCodeSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EditorInlineCodeSpan.kt @@ -1,10 +1,10 @@ -package com.swmansion.reactnativerichtexteditor.spans +package com.swmansion.enriched.spans import android.graphics.Typeface import android.text.TextPaint import android.text.style.BackgroundColorSpan -import com.swmansion.reactnativerichtexteditor.spans.interfaces.EditorInlineSpan -import com.swmansion.reactnativerichtexteditor.styles.RichTextStyle +import com.swmansion.enriched.spans.interfaces.EditorInlineSpan +import com.swmansion.enriched.styles.RichTextStyle class EditorInlineCodeSpan(private val richTextStyle: RichTextStyle) : BackgroundColorSpan(richTextStyle.inlineCodeBackgroundColor), EditorInlineSpan { override fun updateDrawState(textPaint: TextPaint) { diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorItalicSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EditorItalicSpan.kt similarity index 51% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorItalicSpan.kt rename to android/src/main/java/com/swmansion/enriched/spans/EditorItalicSpan.kt index ce9ce7ba2..8f52765a7 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorItalicSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EditorItalicSpan.kt @@ -1,9 +1,9 @@ -package com.swmansion.reactnativerichtexteditor.spans +package com.swmansion.enriched.spans import android.graphics.Typeface import android.text.style.StyleSpan -import com.swmansion.reactnativerichtexteditor.spans.interfaces.EditorInlineSpan -import com.swmansion.reactnativerichtexteditor.styles.RichTextStyle +import com.swmansion.enriched.spans.interfaces.EditorInlineSpan +import com.swmansion.enriched.styles.RichTextStyle @Suppress("UNUSED_PARAMETER") class EditorItalicSpan(private val richTextStyle: RichTextStyle) : StyleSpan(Typeface.ITALIC), EditorInlineSpan { diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorLinkSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EditorLinkSpan.kt similarity index 76% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorLinkSpan.kt rename to android/src/main/java/com/swmansion/enriched/spans/EditorLinkSpan.kt index 96d0e7665..775cd768f 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorLinkSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EditorLinkSpan.kt @@ -1,10 +1,10 @@ -package com.swmansion.reactnativerichtexteditor.spans +package com.swmansion.enriched.spans import android.text.TextPaint import android.text.style.ClickableSpan import android.view.View -import com.swmansion.reactnativerichtexteditor.spans.interfaces.EditorInlineSpan -import com.swmansion.reactnativerichtexteditor.styles.RichTextStyle +import com.swmansion.enriched.spans.interfaces.EditorInlineSpan +import com.swmansion.enriched.styles.RichTextStyle class EditorLinkSpan(private val url: String, private val richTextStyle: RichTextStyle) : ClickableSpan(), EditorInlineSpan { override fun onClick(view: View) { diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorMentionSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EditorMentionSpan.kt similarity index 83% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorMentionSpan.kt rename to android/src/main/java/com/swmansion/enriched/spans/EditorMentionSpan.kt index 51d22d921..bc9ca51ed 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorMentionSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EditorMentionSpan.kt @@ -1,10 +1,10 @@ -package com.swmansion.reactnativerichtexteditor.spans +package com.swmansion.enriched.spans import android.text.TextPaint import android.text.style.ClickableSpan import android.view.View -import com.swmansion.reactnativerichtexteditor.spans.interfaces.EditorInlineSpan -import com.swmansion.reactnativerichtexteditor.styles.RichTextStyle +import com.swmansion.enriched.spans.interfaces.EditorInlineSpan +import com.swmansion.enriched.styles.RichTextStyle class EditorMentionSpan(private val text: String, private val indicator: String, private val attributes: Map, private val richTextStyle: RichTextStyle) : ClickableSpan(), EditorInlineSpan { diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorOrderedListSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EditorOrderedListSpan.kt similarity index 90% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorOrderedListSpan.kt rename to android/src/main/java/com/swmansion/enriched/spans/EditorOrderedListSpan.kt index c3f7821c2..18824ff85 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorOrderedListSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EditorOrderedListSpan.kt @@ -1,12 +1,12 @@ -package com.swmansion.reactnativerichtexteditor.spans +package com.swmansion.enriched.spans import android.graphics.Canvas import android.graphics.Paint import android.graphics.Typeface import android.text.Layout import android.text.style.LeadingMarginSpan -import com.swmansion.reactnativerichtexteditor.spans.interfaces.EditorParagraphSpan -import com.swmansion.reactnativerichtexteditor.styles.RichTextStyle +import com.swmansion.enriched.spans.interfaces.EditorParagraphSpan +import com.swmansion.enriched.styles.RichTextStyle class EditorOrderedListSpan(private var index: Int, private val richTextStyle: RichTextStyle) : LeadingMarginSpan, EditorParagraphSpan { override fun getLeadingMargin(first: Boolean): Int { diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorSpans.kt b/android/src/main/java/com/swmansion/enriched/spans/EditorSpans.kt similarity index 98% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorSpans.kt rename to android/src/main/java/com/swmansion/enriched/spans/EditorSpans.kt index 0cfadf5c9..2e41364aa 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorSpans.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EditorSpans.kt @@ -1,4 +1,4 @@ -package com.swmansion.reactnativerichtexteditor.spans +package com.swmansion.enriched.spans data class BaseSpanConfig(val clazz: Class<*>) data class ParagraphSpanConfig(val clazz: Class<*>, val isContinuous: Boolean) diff --git a/android/src/main/java/com/swmansion/enriched/spans/EditorStrikeThroughSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EditorStrikeThroughSpan.kt new file mode 100644 index 000000000..ff761e5b4 --- /dev/null +++ b/android/src/main/java/com/swmansion/enriched/spans/EditorStrikeThroughSpan.kt @@ -0,0 +1,9 @@ +package com.swmansion.enriched.spans + +import android.text.style.StrikethroughSpan +import com.swmansion.enriched.spans.interfaces.EditorInlineSpan +import com.swmansion.enriched.styles.RichTextStyle + +@Suppress("UNUSED_PARAMETER") +class EditorStrikeThroughSpan(private val richTextStyle: RichTextStyle) : StrikethroughSpan(), EditorInlineSpan { +} diff --git a/android/src/main/java/com/swmansion/enriched/spans/EditorUnderlineSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EditorUnderlineSpan.kt new file mode 100644 index 000000000..52475aca3 --- /dev/null +++ b/android/src/main/java/com/swmansion/enriched/spans/EditorUnderlineSpan.kt @@ -0,0 +1,9 @@ +package com.swmansion.enriched.spans + +import android.text.style.UnderlineSpan +import com.swmansion.enriched.spans.interfaces.EditorInlineSpan +import com.swmansion.enriched.styles.RichTextStyle + +@Suppress("UNUSED_PARAMETER") +class EditorUnderlineSpan(private val richTextStyle: RichTextStyle) : UnderlineSpan(), EditorInlineSpan { +} diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorUnorderedListSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EditorUnorderedListSpan.kt similarity index 86% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorUnorderedListSpan.kt rename to android/src/main/java/com/swmansion/enriched/spans/EditorUnorderedListSpan.kt index 9b7a1c080..9cc4d6880 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorUnorderedListSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EditorUnorderedListSpan.kt @@ -1,12 +1,12 @@ -package com.swmansion.reactnativerichtexteditor.spans +package com.swmansion.enriched.spans import android.graphics.Canvas import android.graphics.Paint import android.text.Layout import android.text.Spanned import android.text.style.LeadingMarginSpan -import com.swmansion.reactnativerichtexteditor.spans.interfaces.EditorParagraphSpan -import com.swmansion.reactnativerichtexteditor.styles.RichTextStyle +import com.swmansion.enriched.spans.interfaces.EditorParagraphSpan +import com.swmansion.enriched.styles.RichTextStyle // https://android.googlesource.com/platform/frameworks/base/+/refs/heads/main/core/java/android/text/style/BulletSpan.java class EditorUnorderedListSpan(private val richTextStyle: RichTextStyle) : LeadingMarginSpan, EditorParagraphSpan { diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/interfaces/EditorBlockSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorBlockSpan.kt similarity index 51% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/interfaces/EditorBlockSpan.kt rename to android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorBlockSpan.kt index c6edbe356..5c0fddd7a 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/interfaces/EditorBlockSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorBlockSpan.kt @@ -1,4 +1,4 @@ -package com.swmansion.reactnativerichtexteditor.spans.interfaces +package com.swmansion.enriched.spans.interfaces interface EditorBlockSpan : EditorSpan, EditorZeroWidthSpaceSpan { } diff --git a/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorHeadingSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorHeadingSpan.kt new file mode 100644 index 000000000..293ab4fd3 --- /dev/null +++ b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorHeadingSpan.kt @@ -0,0 +1,4 @@ +package com.swmansion.enriched.spans.interfaces + +interface EditorHeadingSpan : EditorParagraphSpan { +} diff --git a/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorInlineSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorInlineSpan.kt new file mode 100644 index 000000000..e695a2287 --- /dev/null +++ b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorInlineSpan.kt @@ -0,0 +1,4 @@ +package com.swmansion.enriched.spans.interfaces + +interface EditorInlineSpan : EditorSpan { +} diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/interfaces/EditorParagraphSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorParagraphSpan.kt similarity index 53% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/interfaces/EditorParagraphSpan.kt rename to android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorParagraphSpan.kt index 65a6e98a7..219dc29b4 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/interfaces/EditorParagraphSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorParagraphSpan.kt @@ -1,4 +1,4 @@ -package com.swmansion.reactnativerichtexteditor.spans.interfaces +package com.swmansion.enriched.spans.interfaces interface EditorParagraphSpan : EditorSpan, EditorZeroWidthSpaceSpan { } diff --git a/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorSpan.kt new file mode 100644 index 000000000..094fc06f2 --- /dev/null +++ b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorSpan.kt @@ -0,0 +1,4 @@ +package com.swmansion.enriched.spans.interfaces + +interface EditorSpan { +} diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/interfaces/EditorZeroWidthSpaceSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorZeroWidthSpaceSpan.kt similarity index 69% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/interfaces/EditorZeroWidthSpaceSpan.kt rename to android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorZeroWidthSpaceSpan.kt index 6f2356195..5d1b29079 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/interfaces/EditorZeroWidthSpaceSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorZeroWidthSpaceSpan.kt @@ -1,4 +1,4 @@ -package com.swmansion.reactnativerichtexteditor.spans.interfaces +package com.swmansion.enriched.spans.interfaces // Spans that are prefixed with zero-width space (\u200B) to ensure that they are visible even when empty. interface EditorZeroWidthSpaceSpan { diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/styles/InlineStyles.kt b/android/src/main/java/com/swmansion/enriched/styles/InlineStyles.kt similarity index 92% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/styles/InlineStyles.kt rename to android/src/main/java/com/swmansion/enriched/styles/InlineStyles.kt index 6db9970ac..2866089c8 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/styles/InlineStyles.kt +++ b/android/src/main/java/com/swmansion/enriched/styles/InlineStyles.kt @@ -1,12 +1,12 @@ -package com.swmansion.reactnativerichtexteditor.styles +package com.swmansion.enriched.styles import android.text.Editable import android.text.Spannable -import com.swmansion.reactnativerichtexteditor.ReactNativeRichTextEditorView -import com.swmansion.reactnativerichtexteditor.spans.EditorSpans -import com.swmansion.reactnativerichtexteditor.utils.getSafeSpanBoundaries +import com.swmansion.enriched.EnrichedTextInputView +import com.swmansion.enriched.spans.EditorSpans +import com.swmansion.enriched.utils.getSafeSpanBoundaries -class InlineStyles(private val editorView: ReactNativeRichTextEditorView) { +class InlineStyles(private val editorView: EnrichedTextInputView) { private fun setSpan(spannable: Spannable, type: Class, start: Int, end: Int) { val previousSpanStart = (start - 1).coerceAtLeast(0) val previousSpanEnd = previousSpanStart + 1 diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/styles/ListStyles.kt b/android/src/main/java/com/swmansion/enriched/styles/ListStyles.kt similarity index 90% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/styles/ListStyles.kt rename to android/src/main/java/com/swmansion/enriched/styles/ListStyles.kt index d3fe67477..a183472f7 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/styles/ListStyles.kt +++ b/android/src/main/java/com/swmansion/enriched/styles/ListStyles.kt @@ -1,17 +1,17 @@ -package com.swmansion.reactnativerichtexteditor.styles +package com.swmansion.enriched.styles import android.text.Editable import android.text.Spannable import android.text.SpannableStringBuilder import android.text.Spanned -import com.swmansion.reactnativerichtexteditor.ReactNativeRichTextEditorView -import com.swmansion.reactnativerichtexteditor.spans.EditorOrderedListSpan -import com.swmansion.reactnativerichtexteditor.spans.EditorSpans -import com.swmansion.reactnativerichtexteditor.spans.EditorUnorderedListSpan -import com.swmansion.reactnativerichtexteditor.utils.getParagraphBounds -import com.swmansion.reactnativerichtexteditor.utils.getSafeSpanBoundaries - -class ListStyles(private val editorView: ReactNativeRichTextEditorView) { +import com.swmansion.enriched.EnrichedTextInputView +import com.swmansion.enriched.spans.EditorOrderedListSpan +import com.swmansion.enriched.spans.EditorSpans +import com.swmansion.enriched.spans.EditorUnorderedListSpan +import com.swmansion.enriched.utils.getParagraphBounds +import com.swmansion.enriched.utils.getSafeSpanBoundaries + +class ListStyles(private val editorView: EnrichedTextInputView) { private fun getPreviousParagraphSpan(spannable: Spannable, s: Int, type: Class): T? { if (s <= 0) return null diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/styles/ParagraphStyles.kt b/android/src/main/java/com/swmansion/enriched/styles/ParagraphStyles.kt similarity index 93% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/styles/ParagraphStyles.kt rename to android/src/main/java/com/swmansion/enriched/styles/ParagraphStyles.kt index 99b315a74..7e31af7f8 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/styles/ParagraphStyles.kt +++ b/android/src/main/java/com/swmansion/enriched/styles/ParagraphStyles.kt @@ -1,14 +1,14 @@ -package com.swmansion.reactnativerichtexteditor.styles +package com.swmansion.enriched.styles import android.text.Editable import android.text.Spannable import android.text.SpannableStringBuilder -import com.swmansion.reactnativerichtexteditor.ReactNativeRichTextEditorView -import com.swmansion.reactnativerichtexteditor.spans.EditorSpans -import com.swmansion.reactnativerichtexteditor.utils.getParagraphBounds -import com.swmansion.reactnativerichtexteditor.utils.getSafeSpanBoundaries +import com.swmansion.enriched.EnrichedTextInputView +import com.swmansion.enriched.spans.EditorSpans +import com.swmansion.enriched.utils.getParagraphBounds +import com.swmansion.enriched.utils.getSafeSpanBoundaries -class ParagraphStyles(private val editorView: ReactNativeRichTextEditorView) { +class ParagraphStyles(private val editorView: EnrichedTextInputView) { private fun setSpan(spannable: Spannable, type: Class, start: Int, end: Int) { val span = type.getDeclaredConstructor(RichTextStyle::class.java).newInstance(editorView.richTextStyle) val (safeStart, safeEnd) = spannable.getSafeSpanBoundaries(start, end) diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/styles/ParametrizedStyles.kt b/android/src/main/java/com/swmansion/enriched/styles/ParametrizedStyles.kt similarity index 92% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/styles/ParametrizedStyles.kt rename to android/src/main/java/com/swmansion/enriched/styles/ParametrizedStyles.kt index 107348842..26b5ab6ea 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/styles/ParametrizedStyles.kt +++ b/android/src/main/java/com/swmansion/enriched/styles/ParametrizedStyles.kt @@ -1,19 +1,19 @@ -package com.swmansion.reactnativerichtexteditor.styles +package com.swmansion.enriched.styles import android.net.Uri import android.text.Editable import android.text.Spannable import android.text.SpannableStringBuilder import android.text.Spanned -import com.swmansion.reactnativerichtexteditor.ReactNativeRichTextEditorView -import com.swmansion.reactnativerichtexteditor.spans.EditorImageSpan -import com.swmansion.reactnativerichtexteditor.spans.EditorLinkSpan -import com.swmansion.reactnativerichtexteditor.spans.EditorMentionSpan -import com.swmansion.reactnativerichtexteditor.spans.EditorSpans -import com.swmansion.reactnativerichtexteditor.utils.getSafeSpanBoundaries +import com.swmansion.enriched.EnrichedTextInputView +import com.swmansion.enriched.spans.EditorImageSpan +import com.swmansion.enriched.spans.EditorLinkSpan +import com.swmansion.enriched.spans.EditorMentionSpan +import com.swmansion.enriched.spans.EditorSpans +import com.swmansion.enriched.utils.getSafeSpanBoundaries import java.io.File -class ParametrizedStyles(private val editorView: ReactNativeRichTextEditorView) { +class ParametrizedStyles(private val editorView: EnrichedTextInputView) { private var mentionStart: Int? = null private var isSettingLinkSpan = false diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/styles/RichTextStyle.kt b/android/src/main/java/com/swmansion/enriched/styles/RichTextStyle.kt similarity index 95% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/styles/RichTextStyle.kt rename to android/src/main/java/com/swmansion/enriched/styles/RichTextStyle.kt index 5e427a59f..9b184c2b1 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/styles/RichTextStyle.kt +++ b/android/src/main/java/com/swmansion/enriched/styles/RichTextStyle.kt @@ -1,4 +1,4 @@ -package com.swmansion.reactnativerichtexteditor.styles +package com.swmansion.enriched.styles import android.graphics.Color import com.facebook.react.bridge.ColorPropConverter @@ -6,7 +6,7 @@ import com.facebook.react.bridge.ReactContext import com.facebook.react.bridge.ReadableMap import com.facebook.react.uimanager.PixelUtil import com.facebook.react.views.text.ReactTypefaceUtils.parseFontWeight -import com.swmansion.reactnativerichtexteditor.ReactNativeRichTextEditorView +import com.swmansion.enriched.EnrichedTextInputView import kotlin.Float import kotlin.Int import kotlin.String @@ -14,7 +14,7 @@ import kotlin.math.ceil class RichTextStyle { private var style: ReadableMap? = null - private var editorView: ReactNativeRichTextEditorView? = null + private var editorView: EnrichedTextInputView? = null // Default values are ignored as they are specified on the JS side. // They are specified only because they are required by the constructor. @@ -58,7 +58,7 @@ class RichTextStyle { var mentionsStyle: MutableMap = mutableMapOf() - constructor(editorView: ReactNativeRichTextEditorView?, style: ReadableMap?) { + constructor(editorView: EnrichedTextInputView?, style: ReadableMap?) { this.editorView = editorView this.style = style @@ -169,7 +169,7 @@ class RichTextStyle { throw Error("Specified textDecorationLine value is not supported: $underline. Supported values are 'underline' and 'none'.") } - private fun calculateOlMarginLeft(editorView: ReactNativeRichTextEditorView?, userMargin: Int): Int { + private fun calculateOlMarginLeft(editorView: EnrichedTextInputView?, userMargin: Int): Int { val fontSize = editorView?.fontSize?.toInt() ?: 0 val leadMargin = fontSize / 2 diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/utils/EditorParser.java b/android/src/main/java/com/swmansion/enriched/utils/EditorParser.java similarity index 94% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/utils/EditorParser.java rename to android/src/main/java/com/swmansion/enriched/utils/EditorParser.java index d61af3ee2..e6be35d28 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/utils/EditorParser.java +++ b/android/src/main/java/com/swmansion/enriched/utils/EditorParser.java @@ -1,4 +1,4 @@ -package com.swmansion.reactnativerichtexteditor.utils; +package com.swmansion.enriched.utils; import android.graphics.drawable.Drawable; import android.text.Editable; @@ -10,26 +10,26 @@ import android.text.style.AlignmentSpan; import android.text.style.ParagraphStyle; -import com.swmansion.reactnativerichtexteditor.spans.EditorBlockQuoteSpan; -import com.swmansion.reactnativerichtexteditor.spans.EditorBoldSpan; -import com.swmansion.reactnativerichtexteditor.spans.EditorCodeBlockSpan; -import com.swmansion.reactnativerichtexteditor.spans.EditorH1Span; -import com.swmansion.reactnativerichtexteditor.spans.EditorH2Span; -import com.swmansion.reactnativerichtexteditor.spans.EditorH3Span; -import com.swmansion.reactnativerichtexteditor.spans.EditorImageSpan; -import com.swmansion.reactnativerichtexteditor.spans.EditorInlineCodeSpan; -import com.swmansion.reactnativerichtexteditor.spans.EditorItalicSpan; -import com.swmansion.reactnativerichtexteditor.spans.EditorLinkSpan; -import com.swmansion.reactnativerichtexteditor.spans.EditorMentionSpan; -import com.swmansion.reactnativerichtexteditor.spans.EditorOrderedListSpan; -import com.swmansion.reactnativerichtexteditor.spans.EditorStrikeThroughSpan; -import com.swmansion.reactnativerichtexteditor.spans.EditorUnderlineSpan; -import com.swmansion.reactnativerichtexteditor.spans.EditorUnorderedListSpan; -import com.swmansion.reactnativerichtexteditor.spans.interfaces.EditorBlockSpan; -import com.swmansion.reactnativerichtexteditor.spans.interfaces.EditorParagraphSpan; -import com.swmansion.reactnativerichtexteditor.spans.interfaces.EditorInlineSpan; -import com.swmansion.reactnativerichtexteditor.spans.interfaces.EditorZeroWidthSpaceSpan; -import com.swmansion.reactnativerichtexteditor.styles.RichTextStyle; +import com.swmansion.enriched.spans.EditorBlockQuoteSpan; +import com.swmansion.enriched.spans.EditorBoldSpan; +import com.swmansion.enriched.spans.EditorCodeBlockSpan; +import com.swmansion.enriched.spans.EditorH1Span; +import com.swmansion.enriched.spans.EditorH2Span; +import com.swmansion.enriched.spans.EditorH3Span; +import com.swmansion.enriched.spans.EditorImageSpan; +import com.swmansion.enriched.spans.EditorInlineCodeSpan; +import com.swmansion.enriched.spans.EditorItalicSpan; +import com.swmansion.enriched.spans.EditorLinkSpan; +import com.swmansion.enriched.spans.EditorMentionSpan; +import com.swmansion.enriched.spans.EditorOrderedListSpan; +import com.swmansion.enriched.spans.EditorStrikeThroughSpan; +import com.swmansion.enriched.spans.EditorUnderlineSpan; +import com.swmansion.enriched.spans.EditorUnorderedListSpan; +import com.swmansion.enriched.spans.interfaces.EditorBlockSpan; +import com.swmansion.enriched.spans.interfaces.EditorParagraphSpan; +import com.swmansion.enriched.spans.interfaces.EditorInlineSpan; +import com.swmansion.enriched.spans.interfaces.EditorZeroWidthSpaceSpan; +import com.swmansion.enriched.styles.RichTextStyle; import org.ccil.cowan.tagsoup.HTMLSchema; import org.ccil.cowan.tagsoup.Parser; diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/utils/EditorSelection.kt b/android/src/main/java/com/swmansion/enriched/utils/EditorSelection.kt similarity index 93% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/utils/EditorSelection.kt rename to android/src/main/java/com/swmansion/enriched/utils/EditorSelection.kt index 9cb0036f3..650c7e502 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/utils/EditorSelection.kt +++ b/android/src/main/java/com/swmansion/enriched/utils/EditorSelection.kt @@ -1,19 +1,19 @@ -package com.swmansion.reactnativerichtexteditor.utils +package com.swmansion.enriched.utils import android.text.Editable import android.text.Spannable import com.facebook.react.bridge.ReactContext import com.facebook.react.uimanager.UIManagerHelper -import com.swmansion.reactnativerichtexteditor.ReactNativeRichTextEditorView -import com.swmansion.reactnativerichtexteditor.events.OnChangeSelectionEvent -import com.swmansion.reactnativerichtexteditor.events.OnLinkDetectedEvent -import com.swmansion.reactnativerichtexteditor.events.OnMentionDetectedEvent -import com.swmansion.reactnativerichtexteditor.spans.EditorLinkSpan -import com.swmansion.reactnativerichtexteditor.spans.EditorMentionSpan -import com.swmansion.reactnativerichtexteditor.spans.EditorSpans +import com.swmansion.enriched.EnrichedTextInputView +import com.swmansion.enriched.events.OnChangeSelectionEvent +import com.swmansion.enriched.events.OnLinkDetectedEvent +import com.swmansion.enriched.events.OnMentionDetectedEvent +import com.swmansion.enriched.spans.EditorLinkSpan +import com.swmansion.enriched.spans.EditorMentionSpan +import com.swmansion.enriched.spans.EditorSpans import org.json.JSONObject -class EditorSelection(private val editorView: ReactNativeRichTextEditorView) { +class EditorSelection(private val editorView: EnrichedTextInputView) { var start: Int = 0 var end: Int = 0 diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/utils/EditorSpanSpate.kt b/android/src/main/java/com/swmansion/enriched/utils/EditorSpanSpate.kt similarity index 94% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/utils/EditorSpanSpate.kt rename to android/src/main/java/com/swmansion/enriched/utils/EditorSpanSpate.kt index 549e0221f..b8030f924 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/utils/EditorSpanSpate.kt +++ b/android/src/main/java/com/swmansion/enriched/utils/EditorSpanSpate.kt @@ -1,14 +1,14 @@ -package com.swmansion.reactnativerichtexteditor.utils +package com.swmansion.enriched.utils import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.ReactContext import com.facebook.react.bridge.WritableMap import com.facebook.react.uimanager.UIManagerHelper -import com.swmansion.reactnativerichtexteditor.ReactNativeRichTextEditorView -import com.swmansion.reactnativerichtexteditor.events.OnChangeStateEvent -import com.swmansion.reactnativerichtexteditor.spans.EditorSpans +import com.swmansion.enriched.EnrichedTextInputView +import com.swmansion.enriched.events.OnChangeStateEvent +import com.swmansion.enriched.spans.EditorSpans -class EditorSpanState(private val editorView: ReactNativeRichTextEditorView) { +class EditorSpanState(private val editorView: EnrichedTextInputView) { private var previousPayload: WritableMap? = null var boldStart: Int? = null diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/utils/Utils.kt b/android/src/main/java/com/swmansion/enriched/utils/Utils.kt similarity index 92% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/utils/Utils.kt rename to android/src/main/java/com/swmansion/enriched/utils/Utils.kt index 198be65b5..25d0ff4fc 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/utils/Utils.kt +++ b/android/src/main/java/com/swmansion/enriched/utils/Utils.kt @@ -1,11 +1,11 @@ -package com.swmansion.reactnativerichtexteditor.utils +package com.swmansion.enriched.utils import android.text.Spannable import android.text.SpannableString import android.text.SpannableStringBuilder import android.util.Log -import com.swmansion.reactnativerichtexteditor.spans.interfaces.EditorBlockSpan -import com.swmansion.reactnativerichtexteditor.spans.interfaces.EditorParagraphSpan +import com.swmansion.enriched.spans.interfaces.EditorBlockSpan +import com.swmansion.enriched.spans.interfaces.EditorParagraphSpan import org.json.JSONObject fun jsonStringToStringMap(json: String): Map { diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/watchers/EditorSpanWatcher.kt b/android/src/main/java/com/swmansion/enriched/watchers/EditorSpanWatcher.kt similarity index 76% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/watchers/EditorSpanWatcher.kt rename to android/src/main/java/com/swmansion/enriched/watchers/EditorSpanWatcher.kt index 45fddcb28..4a9f50b28 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/watchers/EditorSpanWatcher.kt +++ b/android/src/main/java/com/swmansion/enriched/watchers/EditorSpanWatcher.kt @@ -1,19 +1,19 @@ -package com.swmansion.reactnativerichtexteditor.watchers +package com.swmansion.enriched.watchers import android.text.SpanWatcher import android.text.Spannable import android.text.style.ParagraphStyle import com.facebook.react.bridge.ReactContext import com.facebook.react.uimanager.UIManagerHelper -import com.swmansion.reactnativerichtexteditor.ReactNativeRichTextEditorView -import com.swmansion.reactnativerichtexteditor.events.OnChangeHtmlEvent -import com.swmansion.reactnativerichtexteditor.spans.EditorOrderedListSpan -import com.swmansion.reactnativerichtexteditor.spans.interfaces.EditorHeadingSpan -import com.swmansion.reactnativerichtexteditor.spans.interfaces.EditorSpan -import com.swmansion.reactnativerichtexteditor.utils.EditorParser -import com.swmansion.reactnativerichtexteditor.utils.getSafeSpanBoundaries +import com.swmansion.enriched.EnrichedTextInputView +import com.swmansion.enriched.events.OnChangeHtmlEvent +import com.swmansion.enriched.spans.EditorOrderedListSpan +import com.swmansion.enriched.spans.interfaces.EditorHeadingSpan +import com.swmansion.enriched.spans.interfaces.EditorSpan +import com.swmansion.enriched.utils.EditorParser +import com.swmansion.enriched.utils.getSafeSpanBoundaries -class EditorSpanWatcher(private val editorView: ReactNativeRichTextEditorView) : SpanWatcher { +class EditorSpanWatcher(private val editorView: EnrichedTextInputView) : SpanWatcher { private var previousHtml: String? = null override fun onSpanAdded(text: Spannable, what: Any, start: Int, end: Int) { diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/watchers/EditorTextWatcher.kt b/android/src/main/java/com/swmansion/enriched/watchers/EditorTextWatcher.kt similarity index 83% rename from android/src/main/java/com/swmansion/reactnativerichtexteditor/watchers/EditorTextWatcher.kt rename to android/src/main/java/com/swmansion/enriched/watchers/EditorTextWatcher.kt index e13ec89e5..32236aefa 100644 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/watchers/EditorTextWatcher.kt +++ b/android/src/main/java/com/swmansion/enriched/watchers/EditorTextWatcher.kt @@ -1,13 +1,13 @@ -package com.swmansion.reactnativerichtexteditor.watchers +package com.swmansion.enriched.watchers import android.text.Editable import android.text.TextWatcher import com.facebook.react.bridge.ReactContext import com.facebook.react.uimanager.UIManagerHelper -import com.swmansion.reactnativerichtexteditor.ReactNativeRichTextEditorView -import com.swmansion.reactnativerichtexteditor.events.OnChangeTextEvent +import com.swmansion.enriched.EnrichedTextInputView +import com.swmansion.enriched.events.OnChangeTextEvent -class EditorTextWatcher(private val editorView: ReactNativeRichTextEditorView) : TextWatcher { +class EditorTextWatcher(private val editorView: EnrichedTextInputView) : TextWatcher { private var endCursorPosition: Int = 0 private var previousTextLength: Int = 0 diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorStrikeThroughSpan.kt b/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorStrikeThroughSpan.kt deleted file mode 100644 index 6868332dd..000000000 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorStrikeThroughSpan.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.swmansion.reactnativerichtexteditor.spans - -import android.text.style.StrikethroughSpan -import com.swmansion.reactnativerichtexteditor.spans.interfaces.EditorInlineSpan -import com.swmansion.reactnativerichtexteditor.styles.RichTextStyle - -@Suppress("UNUSED_PARAMETER") -class EditorStrikeThroughSpan(private val richTextStyle: RichTextStyle) : StrikethroughSpan(), EditorInlineSpan { -} diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorUnderlineSpan.kt b/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorUnderlineSpan.kt deleted file mode 100644 index befd64eed..000000000 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/EditorUnderlineSpan.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.swmansion.reactnativerichtexteditor.spans - -import android.text.style.UnderlineSpan -import com.swmansion.reactnativerichtexteditor.spans.interfaces.EditorInlineSpan -import com.swmansion.reactnativerichtexteditor.styles.RichTextStyle - -@Suppress("UNUSED_PARAMETER") -class EditorUnderlineSpan(private val richTextStyle: RichTextStyle) : UnderlineSpan(), EditorInlineSpan { -} diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/interfaces/EditorHeadingSpan.kt b/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/interfaces/EditorHeadingSpan.kt deleted file mode 100644 index 6fa7a1664..000000000 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/interfaces/EditorHeadingSpan.kt +++ /dev/null @@ -1,4 +0,0 @@ -package com.swmansion.reactnativerichtexteditor.spans.interfaces - -interface EditorHeadingSpan : EditorParagraphSpan { -} diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/interfaces/EditorInlineSpan.kt b/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/interfaces/EditorInlineSpan.kt deleted file mode 100644 index fd9bc4e10..000000000 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/interfaces/EditorInlineSpan.kt +++ /dev/null @@ -1,4 +0,0 @@ -package com.swmansion.reactnativerichtexteditor.spans.interfaces - -interface EditorInlineSpan : EditorSpan { -} diff --git a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/interfaces/EditorSpan.kt b/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/interfaces/EditorSpan.kt deleted file mode 100644 index f9f9b38cb..000000000 --- a/android/src/main/java/com/swmansion/reactnativerichtexteditor/spans/interfaces/EditorSpan.kt +++ /dev/null @@ -1,4 +0,0 @@ -package com.swmansion.reactnativerichtexteditor.spans.interfaces - -interface EditorSpan { -} diff --git a/android/src/main/new_arch/CMakeLists.txt b/android/src/main/new_arch/CMakeLists.txt index e3e12bac2..be99d0f8a 100644 --- a/android/src/main/new_arch/CMakeLists.txt +++ b/android/src/main/new_arch/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.13) set(CMAKE_VERBOSE_MAKEFILE on) -set(LIB_LITERAL RNReactNativeRichTextEditorViewSpec) +set(LIB_LITERAL RNEnrichedTextInputViewSpec) set(LIB_TARGET_NAME react_codegen_${LIB_LITERAL}) set(LIB_ANDROID_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) diff --git a/android/src/main/new_arch/RNReactNativeRichTextEditorViewSpec.cpp b/android/src/main/new_arch/RNEnrichedTextInputViewSpec.cpp similarity index 64% rename from android/src/main/new_arch/RNReactNativeRichTextEditorViewSpec.cpp rename to android/src/main/new_arch/RNEnrichedTextInputViewSpec.cpp index 58b731922..775c9e07c 100644 --- a/android/src/main/new_arch/RNReactNativeRichTextEditorViewSpec.cpp +++ b/android/src/main/new_arch/RNEnrichedTextInputViewSpec.cpp @@ -8,13 +8,13 @@ * @generated by codegen project: GenerateModuleJniCpp.js */ -#include "RNReactNativeRichTextEditorViewSpec.h" +#include "RNEnrichedTextInputViewSpec.h" namespace facebook::react { -std::shared_ptr RNReactNativeRichTextEditorViewSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms) { +std::shared_ptr RNEnrichedTextInputViewSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms) { return nullptr; } diff --git a/android/src/main/new_arch/RNReactNativeRichTextEditorViewSpec.h b/android/src/main/new_arch/RNEnrichedTextInputViewSpec.h similarity index 63% rename from android/src/main/new_arch/RNReactNativeRichTextEditorViewSpec.h rename to android/src/main/new_arch/RNEnrichedTextInputViewSpec.h index cbe6428c4..d37e4e5cc 100644 --- a/android/src/main/new_arch/RNReactNativeRichTextEditorViewSpec.h +++ b/android/src/main/new_arch/RNEnrichedTextInputViewSpec.h @@ -14,13 +14,13 @@ #include #include -#include +#include namespace facebook::react { JSI_EXPORT -std::shared_ptr RNReactNativeRichTextEditorViewSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms); +std::shared_ptr RNEnrichedTextInputViewSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms); } // namespace facebook::react diff --git a/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputComponentDescriptor.h b/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputComponentDescriptor.h new file mode 100644 index 000000000..0e0f51f3c --- /dev/null +++ b/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputComponentDescriptor.h @@ -0,0 +1,35 @@ +#pragma once + +#include "EnrichedTextInputMeasurementManager.h" +#include "EnrichedTextInputShadowNode.h" + +#include + +namespace facebook::react { + +class EnrichedTextInputComponentDescriptor final + : public ConcreteComponentDescriptor { +public: + EnrichedTextInputComponentDescriptor( + const ComponentDescriptorParameters& parameters) + : ConcreteComponentDescriptor(parameters), + measurementsManager_( + std::make_shared( + contextContainer_)) {} + + void adopt(ShadowNode& shadowNode) const override { + ConcreteComponentDescriptor::adopt(shadowNode); + auto& editorShadowNode = static_cast(shadowNode); + + // `EnrichedTextInputShadowNode` uses + // `EnrichedTextInputMeasurementManager` to provide measurements to Yoga. + editorShadowNode.setMeasurementsManager(measurementsManager_); + } + +private: + const std::shared_ptr + measurementsManager_; +}; + +} // namespace facebook::react + diff --git a/android/src/main/new_arch/react/renderer/components/RNReactNativeRichTextEditorViewSpec/RichTextEditorMeasurementManager.cpp b/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.cpp similarity index 85% rename from android/src/main/new_arch/react/renderer/components/RNReactNativeRichTextEditorViewSpec/RichTextEditorMeasurementManager.cpp rename to android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.cpp index d6132cba9..0906ddbb8 100644 --- a/android/src/main/new_arch/react/renderer/components/RNReactNativeRichTextEditorViewSpec/RichTextEditorMeasurementManager.cpp +++ b/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.cpp @@ -1,4 +1,4 @@ -#include "RichTextEditorMeasurementManager.h" +#include "EnrichedTextInputMeasurementManager.h" #include #include @@ -8,9 +8,9 @@ using namespace facebook::jni; namespace facebook::react { - Size RichTextEditorMeasurementManager::measure( + Size EnrichedTextInputMeasurementManager::measure( SurfaceId surfaceId, - const ReactNativeRichTextEditorViewProps& props, + const EnrichedTextInputViewProps& props, LayoutConstraints layoutConstraints) const { const jni::global_ref& fabricUIManager = contextContainer_->at>("FabricUIManager"); @@ -31,7 +31,7 @@ namespace facebook::react { auto minimumSize = layoutConstraints.minimumSize; auto maximumSize = layoutConstraints.maximumSize; - local_ref componentName = make_jstring("ReactNativeRichTextEditorView"); + local_ref componentName = make_jstring("EnrichedTextInputView"); auto measurement = yogaMeassureToSize(measure( fabricUIManager, diff --git a/android/src/main/new_arch/react/renderer/components/RNReactNativeRichTextEditorViewSpec/RichTextEditorMeasurementManager.h b/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.h similarity index 69% rename from android/src/main/new_arch/react/renderer/components/RNReactNativeRichTextEditorViewSpec/RichTextEditorMeasurementManager.h rename to android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.h index d5a56b032..78b79eead 100644 --- a/android/src/main/new_arch/react/renderer/components/RNReactNativeRichTextEditorViewSpec/RichTextEditorMeasurementManager.h +++ b/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.h @@ -4,19 +4,19 @@ #include #include -#include +#include namespace facebook::react { - class RichTextEditorMeasurementManager { + class EnrichedTextInputMeasurementManager { public: - RichTextEditorMeasurementManager( + EnrichedTextInputMeasurementManager( const ContextContainer::Shared& contextContainer) : contextContainer_(contextContainer) {} Size measure( SurfaceId surfaceId, - const ReactNativeRichTextEditorViewProps& props, + const EnrichedTextInputViewProps& props, LayoutConstraints layoutConstraints) const; private: diff --git a/android/src/main/new_arch/react/renderer/components/RNReactNativeRichTextEditorViewSpec/ReactNativeRichTextEditorShadowNode.cpp b/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.cpp similarity index 68% rename from android/src/main/new_arch/react/renderer/components/RNReactNativeRichTextEditorViewSpec/ReactNativeRichTextEditorShadowNode.cpp rename to android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.cpp index c0c424d9f..8d89e816e 100644 --- a/android/src/main/new_arch/react/renderer/components/RNReactNativeRichTextEditorViewSpec/ReactNativeRichTextEditorShadowNode.cpp +++ b/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.cpp @@ -1,11 +1,11 @@ -#include "ReactNativeRichTextEditorShadowNode.h" +#include "EnrichedTextInputShadowNode.h" #include namespace facebook::react { -extern const char ReactNativeRichTextEditorComponentName[] = "ReactNativeRichTextEditorView"; - void ReactNativeRichTextEditorShadowNode::setMeasurementsManager( - const std::shared_ptr& +extern const char EnrichedTextInputComponentName[] = "EnrichedTextInputView"; + void EnrichedTextInputShadowNode::setMeasurementsManager( + const std::shared_ptr& measurementsManager) { ensureUnsealed(); measurementsManager_ = measurementsManager; @@ -13,7 +13,7 @@ extern const char ReactNativeRichTextEditorComponentName[] = "ReactNativeRichTex // Mark layout as dirty after state has been updated // Once layout is marked as dirty, `measureContent` will be called in order to recalculate layout - void ReactNativeRichTextEditorShadowNode::dirtyLayoutIfNeeded() { + void EnrichedTextInputShadowNode::dirtyLayoutIfNeeded() { const auto state = this->getStateData(); const auto counter = state.getForceHeightRecalculationCounter(); @@ -24,7 +24,7 @@ extern const char ReactNativeRichTextEditorComponentName[] = "ReactNativeRichTex } } - Size ReactNativeRichTextEditorShadowNode::measureContent( + Size EnrichedTextInputShadowNode::measureContent( const LayoutContext &layoutContext, const LayoutConstraints &layoutConstraints) const { diff --git a/android/src/main/new_arch/react/renderer/components/RNReactNativeRichTextEditorViewSpec/ReactNativeRichTextEditorShadowNode.h b/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.h similarity index 53% rename from android/src/main/new_arch/react/renderer/components/RNReactNativeRichTextEditorViewSpec/ReactNativeRichTextEditorShadowNode.h rename to android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.h index 025eeb582..6ff3e3ce6 100644 --- a/android/src/main/new_arch/react/renderer/components/RNReactNativeRichTextEditorViewSpec/ReactNativeRichTextEditorShadowNode.h +++ b/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.h @@ -1,28 +1,28 @@ #pragma once -#include "RichTextEditorMeasurementManager.h" -#include "ReactNativeRichTextEditorViewState.h" +#include "EnrichedTextInputMeasurementManager.h" +#include "EnrichedTextInputState.h" #include -#include -#include +#include +#include namespace facebook::react { -JSI_EXPORT extern const char ReactNativeRichTextEditorComponentName[]; +JSI_EXPORT extern const char EnrichedTextInputComponentName[]; /* - * `ShadowNode` for component. + * `ShadowNode` for component. */ -class ReactNativeRichTextEditorShadowNode final : public ConcreteViewShadowNode< - ReactNativeRichTextEditorComponentName, - ReactNativeRichTextEditorViewProps, - ReactNativeRichTextEditorViewEventEmitter, - ReactNativeRichTextEditorViewState> { +class EnrichedTextInputShadowNode final : public ConcreteViewShadowNode< + EnrichedTextInputComponentName, + EnrichedTextInputViewProps, + EnrichedTextInputViewEventEmitter, + EnrichedTextInputState> { public: using ConcreteViewShadowNode::ConcreteViewShadowNode; // This constructor is called when we "update" shadow node, e.g. after updating shadow node's state - ReactNativeRichTextEditorShadowNode( + EnrichedTextInputShadowNode( ShadowNode const &sourceShadowNode, ShadowNodeFragment const &fragment) : ConcreteViewShadowNode(sourceShadowNode, fragment) { @@ -36,9 +36,9 @@ class ReactNativeRichTextEditorShadowNode final : public ConcreteViewShadowNode< return traits; } - // Associates a shared `RichTextEditorMeasurementManager` with the node. + // Associates a shared `EnrichedTextInputMeasurementManager` with the node. void setMeasurementsManager( - const std::shared_ptr& + const std::shared_ptr& measurementsManager); void dirtyLayoutIfNeeded(); @@ -49,6 +49,6 @@ class ReactNativeRichTextEditorShadowNode final : public ConcreteViewShadowNode< private: int forceHeightRecalculationCounter_; - std::shared_ptr measurementsManager_; + std::shared_ptr measurementsManager_; }; } // namespace facebook::react diff --git a/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.cpp b/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.cpp new file mode 100644 index 000000000..31287bd87 --- /dev/null +++ b/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.cpp @@ -0,0 +1,9 @@ +#include "EnrichedTextInputState.h" + +namespace facebook::react { + + int EnrichedTextInputState::getForceHeightRecalculationCounter() const { + return forceHeightRecalculationCounter_; + } + +} diff --git a/android/src/main/new_arch/react/renderer/components/RNReactNativeRichTextEditorViewSpec/ReactNativeRichTextEditorViewState.h b/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.h similarity index 71% rename from android/src/main/new_arch/react/renderer/components/RNReactNativeRichTextEditorViewSpec/ReactNativeRichTextEditorViewState.h rename to android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.h index dc0f68fe1..31980e453 100644 --- a/android/src/main/new_arch/react/renderer/components/RNReactNativeRichTextEditorViewSpec/ReactNativeRichTextEditorViewState.h +++ b/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.h @@ -4,13 +4,13 @@ namespace facebook::react { - class ReactNativeRichTextEditorViewState { + class EnrichedTextInputState { public: - ReactNativeRichTextEditorViewState() + EnrichedTextInputState() : forceHeightRecalculationCounter_(0) {} // Used by Kotlin to set current text value - ReactNativeRichTextEditorViewState(ReactNativeRichTextEditorViewState const &previousState, folly::dynamic data) + EnrichedTextInputState(EnrichedTextInputState const &previousState, folly::dynamic data) : forceHeightRecalculationCounter_((int)data["forceHeightRecalculationCounter"].getInt()){}; folly::dynamic getDynamic() const { return {}; diff --git a/android/src/main/new_arch/react/renderer/components/RNReactNativeRichTextEditorViewSpec/ReactNativeRichTextEditorViewComponentDescriptor.h b/android/src/main/new_arch/react/renderer/components/RNReactNativeRichTextEditorViewSpec/ReactNativeRichTextEditorViewComponentDescriptor.h deleted file mode 100644 index 02d5a5dfd..000000000 --- a/android/src/main/new_arch/react/renderer/components/RNReactNativeRichTextEditorViewSpec/ReactNativeRichTextEditorViewComponentDescriptor.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include "RichTextEditorMeasurementManager.h" -#include "ReactNativeRichTextEditorShadowNode.h" - -#include - -namespace facebook::react { - -class ReactNativeRichTextEditorViewComponentDescriptor final - : public ConcreteComponentDescriptor { -public: - ReactNativeRichTextEditorViewComponentDescriptor( - const ComponentDescriptorParameters& parameters) - : ConcreteComponentDescriptor(parameters), - measurementsManager_( - std::make_shared( - contextContainer_)) {} - - void adopt(ShadowNode& shadowNode) const override { - ConcreteComponentDescriptor::adopt(shadowNode); - auto& editorShadowNode = static_cast(shadowNode); - - // `ReactNativeRichTextEditorShadowNode` uses - // `RichTextEditorMeasurementManager` to provide measurements to Yoga. - editorShadowNode.setMeasurementsManager(measurementsManager_); - } - -private: - const std::shared_ptr - measurementsManager_; -}; - -} // namespace facebook::react - diff --git a/android/src/main/new_arch/react/renderer/components/RNReactNativeRichTextEditorViewSpec/ReactNativeRichTextEditorViewState.cpp b/android/src/main/new_arch/react/renderer/components/RNReactNativeRichTextEditorViewSpec/ReactNativeRichTextEditorViewState.cpp deleted file mode 100644 index 54295d2cf..000000000 --- a/android/src/main/new_arch/react/renderer/components/RNReactNativeRichTextEditorViewSpec/ReactNativeRichTextEditorViewState.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "ReactNativeRichTextEditorViewState.h" - -namespace facebook::react { - - int ReactNativeRichTextEditorViewState::getForceHeightRecalculationCounter() const { - return forceHeightRecalculationCounter_; - } - -} diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index ed3a6061f..57f92c43b 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -77,9 +77,9 @@ android { buildToolsVersion rootProject.ext.buildToolsVersion compileSdk rootProject.ext.compileSdkVersion - namespace "swmansion.reactnativerichtexteditor.example" + namespace "swmansion.enriched.example" defaultConfig { - applicationId "swmansion.reactnativerichtexteditor.example" + applicationId "swmansion.enriched.example" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 1 diff --git a/example/android/app/src/main/java/swmansion/reactnativerichtexteditor/example/MainActivity.kt b/example/android/app/src/main/java/swmansion/enriched/example/MainActivity.kt similarity index 85% rename from example/android/app/src/main/java/swmansion/reactnativerichtexteditor/example/MainActivity.kt rename to example/android/app/src/main/java/swmansion/enriched/example/MainActivity.kt index 58e64e5c0..e234b0c52 100644 --- a/example/android/app/src/main/java/swmansion/reactnativerichtexteditor/example/MainActivity.kt +++ b/example/android/app/src/main/java/swmansion/enriched/example/MainActivity.kt @@ -1,4 +1,4 @@ -package swmansion.reactnativerichtexteditor.example +package swmansion.enriched.example import com.facebook.react.ReactActivity import com.facebook.react.ReactActivityDelegate @@ -11,7 +11,7 @@ class MainActivity : ReactActivity() { * Returns the name of the main component registered from JavaScript. This is used to schedule * rendering of the component. */ - override fun getMainComponentName(): String = "ReactNativeRichTextEditorExample" + override fun getMainComponentName(): String = "EnrichedTextInputExample" /** * Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate] diff --git a/example/android/app/src/main/java/swmansion/reactnativerichtexteditor/example/MainApplication.kt b/example/android/app/src/main/java/swmansion/enriched/example/MainApplication.kt similarity index 96% rename from example/android/app/src/main/java/swmansion/reactnativerichtexteditor/example/MainApplication.kt rename to example/android/app/src/main/java/swmansion/enriched/example/MainApplication.kt index 4541cb8bb..af3b37d7a 100644 --- a/example/android/app/src/main/java/swmansion/reactnativerichtexteditor/example/MainApplication.kt +++ b/example/android/app/src/main/java/swmansion/enriched/example/MainApplication.kt @@ -1,4 +1,4 @@ -package swmansion.reactnativerichtexteditor.example +package swmansion.enriched.example import android.app.Application import com.facebook.react.PackageList diff --git a/example/android/app/src/main/res/values/strings.xml b/example/android/app/src/main/res/values/strings.xml index 146b5853b..312ad6f15 100644 --- a/example/android/app/src/main/res/values/strings.xml +++ b/example/android/app/src/main/res/values/strings.xml @@ -1,3 +1,3 @@ - ReactNativeRichTextEditorExample + ReactNativeEnrichedExample diff --git a/example/android/settings.gradle b/example/android/settings.gradle index ee29500aa..654eb0af1 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -1,6 +1,6 @@ pluginManagement { includeBuild("../node_modules/@react-native/gradle-plugin") } plugins { id("com.facebook.react.settings") } extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() } -rootProject.name = 'swmansion.reactnativerichtexteditor.example' +rootProject.name = 'swmansion.enriched.example' include ':app' includeBuild('../node_modules/@react-native/gradle-plugin') diff --git a/example/app.json b/example/app.json index 6f96d1ab6..d9ebebe7f 100644 --- a/example/app.json +++ b/example/app.json @@ -1,4 +1,4 @@ { - "name": "ReactNativeRichTextEditorExample", - "displayName": "ReactNativeRichTextEditorExample" + "name": "EnrichedTextInputExample", + "displayName": "ReactNativeEnrichedExample" } diff --git a/example/package.json b/example/package.json index 8ee70e617..0cbafa48e 100644 --- a/example/package.json +++ b/example/package.json @@ -1,5 +1,5 @@ { - "name": "@swmansion/react-native-rich-text-editor-example", + "name": "react-native-enriched-example", "version": "0.0.1", "private": true, "scripts": { diff --git a/example/src/App.tsx b/example/src/App.tsx index 60da641f4..a265374a9 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -7,16 +7,16 @@ import { ScrollView, } from 'react-native'; import { - RichTextInput, + EnrichedTextInput, type OnChangeTextEvent, - type RichTextInputInstance, + type EnrichedTextInputInstance, type OnLinkDetected, type OnChangeMentionEvent, type OnChangeHtmlEvent, type OnChangeStateEvent, type OnChangeSelectionEvent, - type RichTextStyle, -} from '@swmansion/react-native-rich-text-editor'; + type HtmlStyle, +} from 'react-native-enriched'; import { useRef, useState } from 'react'; import { Button } from './components/Button'; import { Toolbar } from './components/Toolbar'; @@ -74,7 +74,7 @@ export default function App() { const [currentLink, setCurrentLink] = useState(DEFAULT_LINK_STATE); - const ref = useRef(null); + const ref = useRef(null); const userMention = useUserMention(); const channelMention = useChannelMention(); @@ -217,12 +217,12 @@ export default function App() { > SWM Rich Text Editor - ; + editorRef?: React.RefObject; onOpenLinkModal: () => void; onSelectImage: () => void; } diff --git a/package.json b/package.json index c167b500d..4ff730df8 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@swmansion/react-native-rich-text-editor", + "name": "react-native-enriched", "version": "0.1.0", "description": "Rich Text Editor component for React Native", "source": "./src/index.tsx", @@ -32,7 +32,7 @@ "!**/.*" ], "scripts": { - "example": "yarn workspace @swmansion/react-native-rich-text-editor-example", + "example": "yarn workspace react-native-enriched-example", "test": "jest --passWithNoTests", "typecheck": "tsc", "lint": "eslint \"**/*.{js,ts,tsx}\"", @@ -150,7 +150,7 @@ ] }, "codegenConfig": { - "name": "RNReactNativeRichTextEditorViewSpec", + "name": "RNEnrichedTextInputViewSpec", "type": "components", "jsSrcsDir": "src", "outputDir": { @@ -158,7 +158,7 @@ "android": "android/generated" }, "android": { - "javaPackageName": "com.swmansion.reactnativerichtexteditor" + "javaPackageName": "com.swmansion.enriched" }, "ios": { "componentProvider": { diff --git a/react-native.config.js b/react-native.config.js index eeec5edbb..644afea89 100644 --- a/react-native.config.js +++ b/react-native.config.js @@ -6,9 +6,7 @@ module.exports = { platforms: { android: { cmakeListsPath: '../android/src/main/new_arch/CMakeLists.txt', - componentDescriptors: [ - 'ReactNativeRichTextEditorViewComponentDescriptor', - ], + componentDescriptors: ['EnrichedTextInputComponentDescriptor'], }, }, }, diff --git a/src/RichTextInput.tsx b/src/EnrichedTextInput.tsx similarity index 92% rename from src/RichTextInput.tsx rename to src/EnrichedTextInput.tsx index ad042b001..0079d60b0 100644 --- a/src/RichTextInput.tsx +++ b/src/EnrichedTextInput.tsx @@ -5,7 +5,7 @@ import { useMemo, useRef, } from 'react'; -import ReactNativeRichTextEditorView, { +import EnrichedTextInputNativeComponent, { Commands, type NativeProps, type OnChangeHtmlEvent, @@ -17,7 +17,7 @@ import ReactNativeRichTextEditorView, { type OnMentionDetected, type OnMentionDetectedInternal, type MentionStyleProperties, -} from './ReactNativeRichTextEditorViewNativeComponent'; +} from './EnrichedTextInputNativeComponent'; import type { ColorValue, HostInstance, @@ -30,9 +30,9 @@ import type { ViewProps, ViewStyle, } from 'react-native'; -import { normalizeRichTextStyle } from './normalizeRichTextStyle'; +import { normalizeHtmlStyle } from './normalizeHtmlStyle'; -export interface RichTextInputInstance extends NativeMethods { +export interface EnrichedTextInputInstance extends NativeMethods { // General commands focus: () => void; blur: () => void; @@ -66,7 +66,7 @@ export interface OnChangeMentionEvent { text: string; } -export interface RichTextStyle { +export interface HtmlStyle { h1?: { fontSize?: number; bold?: boolean; @@ -117,8 +117,8 @@ export interface RichTextStyle { }; } -export interface RichTextInputProps extends Omit { - ref?: RefObject; +export interface EnrichedTextInputProps extends Omit { + ref?: RefObject; autoFocus?: boolean; editable?: boolean; mentionIndicators?: string[]; @@ -128,7 +128,7 @@ export interface RichTextInputProps extends Omit { cursorColor?: ColorValue; selectionColor?: ColorValue; autocapitalize?: 'none' | 'sentences' | 'words' | 'characters'; - richTextStyle?: RichTextStyle; + htmlStyle?: HtmlStyle; style?: ViewStyle | TextStyle; onFocus?: () => void; onBlur?: () => void; @@ -159,7 +159,7 @@ const warnAboutMissconfiguredMentions = (indicator: string) => { type ComponentType = (Component & NativeMethods) | null; -export const RichTextInput = ({ +export const EnrichedTextInput = ({ ref, autoFocus, editable = true, @@ -171,7 +171,7 @@ export const RichTextInput = ({ selectionColor, style, autocapitalize = 'sentences', - richTextStyle = {}, + htmlStyle = {}, onFocus, onBlur, onChangeText, @@ -184,12 +184,12 @@ export const RichTextInput = ({ onEndMention, onChangeSelection, ...rest -}: RichTextInputProps) => { +}: EnrichedTextInputProps) => { const nativeRef = useRef(null); - const normalizedRichTextStyle = useMemo( - () => normalizeRichTextStyle(richTextStyle, mentionIndicators), - [richTextStyle, mentionIndicators] + const normalizedHtmlStyle = useMemo( + () => normalizeHtmlStyle(htmlStyle, mentionIndicators), + [htmlStyle, mentionIndicators] ); useImperativeHandle(ref, () => ({ @@ -317,7 +317,7 @@ export const RichTextInput = ({ }; return ( - ; @@ -227,9 +227,6 @@ export const Commands: NativeCommands = codegenNativeCommands({ ], }); -export default codegenNativeComponent( - 'ReactNativeRichTextEditorView', - { - interfaceOnly: true, - } -) as HostComponent; +export default codegenNativeComponent('EnrichedTextInputView', { + interfaceOnly: true, +}) as HostComponent; diff --git a/src/index.tsx b/src/index.tsx index d9456a592..82b37a072 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,4 +1,4 @@ -export * from './RichTextInput'; +export * from './EnrichedTextInput'; export type { OnChangeTextEvent, OnChangeHtmlEvent, @@ -6,4 +6,4 @@ export type { OnLinkDetected, OnMentionDetected, OnChangeSelectionEvent, -} from './ReactNativeRichTextEditorViewNativeComponent'; +} from './EnrichedTextInputNativeComponent'; diff --git a/src/normalizeRichTextStyle.ts b/src/normalizeHtmlStyle.ts similarity index 82% rename from src/normalizeRichTextStyle.ts rename to src/normalizeHtmlStyle.ts index 839e43dfc..96a7053ea 100644 --- a/src/normalizeRichTextStyle.ts +++ b/src/normalizeHtmlStyle.ts @@ -1,11 +1,11 @@ -import type { RichTextStyle } from './RichTextInput'; +import type { HtmlStyle } from './EnrichedTextInput'; import { type ColorValue, processColor } from 'react-native'; import type { MentionStyleProperties, - RichTextStyleInternal, -} from './ReactNativeRichTextEditorViewNativeComponent'; + HtmlStyleInternal, +} from './EnrichedTextInputNativeComponent'; -const defaultStyle: Required = { +const defaultStyle: Required = { h1: { fontSize: 32, bold: false, @@ -61,7 +61,7 @@ const defaultStyle: Required = { }; const isMentionStyleRecord = ( - mentionStyle: RichTextStyle['mention'] + mentionStyle: HtmlStyle['mention'] ): mentionStyle is Record => { if ( mentionStyle && @@ -82,10 +82,10 @@ const isMentionStyleRecord = ( return false; }; -const convertToRichTextStyleInternal = ( - style: RichTextStyle, +const convertToHtmlStyleInternal = ( + style: HtmlStyle, mentionIndicators: string[] -): RichTextStyleInternal => { +): HtmlStyleInternal => { const mentionStyles: Record = {}; mentionIndicators.forEach((indicator) => { @@ -118,9 +118,7 @@ const convertToRichTextStyleInternal = ( }; }; -const assignDefaultValues = ( - style: RichTextStyleInternal -): RichTextStyleInternal => { +const assignDefaultValues = (style: HtmlStyleInternal): HtmlStyleInternal => { const merged: Record = { ...defaultStyle }; for (const key in style) { @@ -133,8 +131,8 @@ const assignDefaultValues = ( } merged[key] = { - ...defaultStyle[key as keyof RichTextStyle], - ...(style[key as keyof RichTextStyle] as object), + ...defaultStyle[key as keyof HtmlStyle], + ...(style[key as keyof HtmlStyle] as object), }; } @@ -149,7 +147,7 @@ const parseStyle = (name: string, value: unknown) => { return processColor(value as ColorValue); }; -const parseColors = (style: RichTextStyleInternal): RichTextStyleInternal => { +const parseColors = (style: HtmlStyleInternal): HtmlStyleInternal => { const finalStyle: Record = {}; for (const [tagName, tagStyle] of Object.entries(style)) { @@ -180,11 +178,11 @@ const parseColors = (style: RichTextStyleInternal): RichTextStyleInternal => { return finalStyle; }; -export const normalizeRichTextStyle = ( - style: RichTextStyle, +export const normalizeHtmlStyle = ( + style: HtmlStyle, mentionIndicators: string[] -): RichTextStyleInternal => { - const converted = convertToRichTextStyleInternal(style, mentionIndicators); +): HtmlStyleInternal => { + const converted = convertToHtmlStyleInternal(style, mentionIndicators); const withDefaults = assignDefaultValues(converted); return parseColors(withDefaults); }; diff --git a/tsconfig.json b/tsconfig.json index 59b5b80d8..f8d112b29 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "rootDir": ".", "paths": { - "@swmansion/react-native-rich-text-editor": ["./src/index"] + "react-native-enriched": ["./src/index"] }, "allowUnreachableCode": false, "allowUnusedLabels": false, diff --git a/yarn.lock b/yarn.lock index 7f3a9dfa8..4319fdbfe 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3005,60 +3005,6 @@ __metadata: languageName: node linkType: hard -"@swmansion/react-native-rich-text-editor-example@workspace:example": - version: 0.0.0-use.local - resolution: "@swmansion/react-native-rich-text-editor-example@workspace:example" - dependencies: - "@babel/core": ^7.25.2 - "@babel/preset-env": ^7.25.3 - "@babel/runtime": ^7.25.0 - "@react-native-community/cli": 20.0.0 - "@react-native-community/cli-platform-android": 20.0.0 - "@react-native-community/cli-platform-ios": 20.0.0 - "@react-native/babel-preset": 0.81.0 - "@react-native/metro-config": 0.81.0 - "@react-native/typescript-config": 0.81.0 - "@types/react": ^19.1.0 - react: 19.1.0 - react-native: 0.81.0 - react-native-builder-bob: ^0.40.13 - react-native-image-picker: ^8.2.1 - languageName: unknown - linkType: soft - -"@swmansion/react-native-rich-text-editor@workspace:.": - version: 0.0.0-use.local - resolution: "@swmansion/react-native-rich-text-editor@workspace:." - dependencies: - "@commitlint/config-conventional": ^19.6.0 - "@eslint/compat": ^1.2.7 - "@eslint/eslintrc": ^3.3.0 - "@eslint/js": ^9.22.0 - "@evilmartians/lefthook": ^1.5.0 - "@react-native-community/cli": 20.0.0 - "@react-native/eslint-config": ^0.81.0 - "@release-it/conventional-changelog": ^9.0.2 - "@types/jest": ^29.5.5 - "@types/react": ^19.1.0 - commitlint: ^19.6.1 - del-cli: ^5.1.0 - eslint: ^9.22.0 - eslint-config-prettier: ^10.1.1 - eslint-plugin-prettier: ^5.2.3 - jest: ^29.7.0 - prettier: ^3.0.3 - react: 19.1.0 - react-native: 0.81.0 - react-native-builder-bob: ^0.40.6 - release-it: ^17.10.0 - turbo: ^1.10.7 - typescript: ^5.8.3 - peerDependencies: - react: "*" - react-native: "*" - languageName: unknown - linkType: soft - "@tootallnate/quickjs-emscripten@npm:^0.23.0": version: 0.23.0 resolution: "@tootallnate/quickjs-emscripten@npm:0.23.0" @@ -10561,6 +10507,60 @@ __metadata: languageName: node linkType: hard +"react-native-enriched-example@workspace:example": + version: 0.0.0-use.local + resolution: "react-native-enriched-example@workspace:example" + dependencies: + "@babel/core": ^7.25.2 + "@babel/preset-env": ^7.25.3 + "@babel/runtime": ^7.25.0 + "@react-native-community/cli": 20.0.0 + "@react-native-community/cli-platform-android": 20.0.0 + "@react-native-community/cli-platform-ios": 20.0.0 + "@react-native/babel-preset": 0.81.0 + "@react-native/metro-config": 0.81.0 + "@react-native/typescript-config": 0.81.0 + "@types/react": ^19.1.0 + react: 19.1.0 + react-native: 0.81.0 + react-native-builder-bob: ^0.40.13 + react-native-image-picker: ^8.2.1 + languageName: unknown + linkType: soft + +"react-native-enriched@workspace:.": + version: 0.0.0-use.local + resolution: "react-native-enriched@workspace:." + dependencies: + "@commitlint/config-conventional": ^19.6.0 + "@eslint/compat": ^1.2.7 + "@eslint/eslintrc": ^3.3.0 + "@eslint/js": ^9.22.0 + "@evilmartians/lefthook": ^1.5.0 + "@react-native-community/cli": 20.0.0 + "@react-native/eslint-config": ^0.81.0 + "@release-it/conventional-changelog": ^9.0.2 + "@types/jest": ^29.5.5 + "@types/react": ^19.1.0 + commitlint: ^19.6.1 + del-cli: ^5.1.0 + eslint: ^9.22.0 + eslint-config-prettier: ^10.1.1 + eslint-plugin-prettier: ^5.2.3 + jest: ^29.7.0 + prettier: ^3.0.3 + react: 19.1.0 + react-native: 0.81.0 + react-native-builder-bob: ^0.40.6 + release-it: ^17.10.0 + turbo: ^1.10.7 + typescript: ^5.8.3 + peerDependencies: + react: "*" + react-native: "*" + languageName: unknown + linkType: soft + "react-native-image-picker@npm:^8.2.1": version: 8.2.1 resolution: "react-native-image-picker@npm:8.2.1" From 75c338d01493415cda277472a0a40803dd743186 Mon Sep 17 00:00:00 2001 From: Igor Furgala Date: Fri, 29 Aug 2025 10:22:54 +0200 Subject: [PATCH 2/8] chore: final naming - android --- .../enriched/EnrichedTextInputView.kt | 137 +++++++------- ... => EnrichedTextInputViewLayoutManager.kt} | 8 +- .../enriched/EnrichedTextInputViewManager.kt | 32 ++-- ...age.kt => EnrichedTextInputViewPackage.kt} | 0 .../enriched/events/MentionHandler.kt | 8 +- .../enriched/spans/EditorBoldSpan.kt | 10 -- .../enriched/spans/EditorItalicSpan.kt | 10 -- .../enriched/spans/EditorLinkSpan.kt | 24 --- .../enriched/spans/EditorStrikeThroughSpan.kt | 9 - .../enriched/spans/EditorUnderlineSpan.kt | 9 - ...QuoteSpan.kt => EnrichedBlockQuoteSpan.kt} | 14 +- .../enriched/spans/EnrichedBoldSpan.kt | 10 ++ ...eBlockSpan.kt => EnrichedCodeBlockSpan.kt} | 12 +- .../{EditorH1Span.kt => EnrichedH1Span.kt} | 6 +- .../{EditorH2Span.kt => EnrichedH2Span.kt} | 8 +- .../{EditorH3Span.kt => EnrichedH3Span.kt} | 8 +- ...ditorImageSpan.kt => EnrichedImageSpan.kt} | 18 +- ...eCodeSpan.kt => EnrichedInlineCodeSpan.kt} | 8 +- .../enriched/spans/EnrichedItalicSpan.kt | 10 ++ .../enriched/spans/EnrichedLinkSpan.kt | 24 +++ ...rMentionSpan.kt => EnrichedMentionSpan.kt} | 12 +- ...ListSpan.kt => EnrichedOrderedListSpan.kt} | 14 +- .../{EditorSpans.kt => EnrichedSpans.kt} | 32 ++-- .../spans/EnrichedStrikeThroughSpan.kt | 9 + .../enriched/spans/EnrichedUnderlineSpan.kt | 9 + ...stSpan.kt => EnrichedUnorderedListSpan.kt} | 18 +- .../spans/interfaces/EditorBlockSpan.kt | 4 - .../spans/interfaces/EditorHeadingSpan.kt | 4 - .../spans/interfaces/EditorParagraphSpan.kt | 4 - .../spans/interfaces/EnrichedBlockSpan.kt | 4 + .../spans/interfaces/EnrichedHeadingSpan.kt | 4 + ...torInlineSpan.kt => EnrichedInlineSpan.kt} | 2 +- .../spans/interfaces/EnrichedParagraphSpan.kt | 4 + .../{EditorSpan.kt => EnrichedSpan.kt} | 2 +- ...eSpan.kt => EnrichedZeroWidthSpaceSpan.kt} | 2 +- .../styles/{RichTextStyle.kt => HtmlStyle.kt} | 16 +- .../swmansion/enriched/styles/InlineStyles.kt | 32 ++-- .../swmansion/enriched/styles/ListStyles.kt | 54 +++--- .../enriched/styles/ParagraphStyles.kt | 38 ++-- .../enriched/styles/ParametrizedStyles.kt | 72 ++++---- .../enriched/utils/EditorSelection.kt | 72 ++++---- .../enriched/utils/EditorSpanSpate.kt | 72 ++++---- ...{EditorParser.java => EnrichedParser.java} | 170 +++++++++--------- .../com/swmansion/enriched/utils/Utils.kt | 14 +- ...rSpanWatcher.kt => EnrichedSpanWatcher.kt} | 28 +-- ...rTextWatcher.kt => EnrichedTextWatcher.kt} | 24 +-- 46 files changed, 540 insertions(+), 541 deletions(-) rename android/src/main/java/com/swmansion/enriched/{ReactNativeRichTextEditorViewLayoutManager.kt => EnrichedTextInputViewLayoutManager.kt} (88%) rename android/src/main/java/com/swmansion/enriched/{ReactNativeRichTextEditorPackage.kt => EnrichedTextInputViewPackage.kt} (100%) delete mode 100644 android/src/main/java/com/swmansion/enriched/spans/EditorBoldSpan.kt delete mode 100644 android/src/main/java/com/swmansion/enriched/spans/EditorItalicSpan.kt delete mode 100644 android/src/main/java/com/swmansion/enriched/spans/EditorLinkSpan.kt delete mode 100644 android/src/main/java/com/swmansion/enriched/spans/EditorStrikeThroughSpan.kt delete mode 100644 android/src/main/java/com/swmansion/enriched/spans/EditorUnderlineSpan.kt rename android/src/main/java/com/swmansion/enriched/spans/{EditorBlockQuoteSpan.kt => EnrichedBlockQuoteSpan.kt} (61%) create mode 100644 android/src/main/java/com/swmansion/enriched/spans/EnrichedBoldSpan.kt rename android/src/main/java/com/swmansion/enriched/spans/{EditorCodeBlockSpan.kt => EnrichedCodeBlockSpan.kt} (63%) rename android/src/main/java/com/swmansion/enriched/spans/{EditorH1Span.kt => EnrichedH1Span.kt} (60%) rename android/src/main/java/com/swmansion/enriched/spans/{EditorH2Span.kt => EnrichedH2Span.kt} (53%) rename android/src/main/java/com/swmansion/enriched/spans/{EditorH3Span.kt => EnrichedH3Span.kt} (53%) rename android/src/main/java/com/swmansion/enriched/spans/{EditorImageSpan.kt => EnrichedImageSpan.kt} (54%) rename android/src/main/java/com/swmansion/enriched/spans/{EditorInlineCodeSpan.kt => EnrichedInlineCodeSpan.kt} (50%) create mode 100644 android/src/main/java/com/swmansion/enriched/spans/EnrichedItalicSpan.kt create mode 100644 android/src/main/java/com/swmansion/enriched/spans/EnrichedLinkSpan.kt rename android/src/main/java/com/swmansion/enriched/spans/{EditorMentionSpan.kt => EnrichedMentionSpan.kt} (60%) rename android/src/main/java/com/swmansion/enriched/spans/{EditorOrderedListSpan.kt => EnrichedOrderedListSpan.kt} (73%) rename android/src/main/java/com/swmansion/enriched/spans/{EditorSpans.kt => EnrichedSpans.kt} (75%) create mode 100644 android/src/main/java/com/swmansion/enriched/spans/EnrichedStrikeThroughSpan.kt create mode 100644 android/src/main/java/com/swmansion/enriched/spans/EnrichedUnderlineSpan.kt rename android/src/main/java/com/swmansion/enriched/spans/{EditorUnorderedListSpan.kt => EnrichedUnorderedListSpan.kt} (59%) delete mode 100644 android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorBlockSpan.kt delete mode 100644 android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorHeadingSpan.kt delete mode 100644 android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorParagraphSpan.kt create mode 100644 android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedBlockSpan.kt create mode 100644 android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedHeadingSpan.kt rename android/src/main/java/com/swmansion/enriched/spans/interfaces/{EditorInlineSpan.kt => EnrichedInlineSpan.kt} (52%) create mode 100644 android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedParagraphSpan.kt rename android/src/main/java/com/swmansion/enriched/spans/interfaces/{EditorSpan.kt => EnrichedSpan.kt} (67%) rename android/src/main/java/com/swmansion/enriched/spans/interfaces/{EditorZeroWidthSpaceSpan.kt => EnrichedZeroWidthSpaceSpan.kt} (80%) rename android/src/main/java/com/swmansion/enriched/styles/{RichTextStyle.kt => HtmlStyle.kt} (93%) rename android/src/main/java/com/swmansion/enriched/utils/{EditorParser.java => EnrichedParser.java} (80%) rename android/src/main/java/com/swmansion/enriched/watchers/{EditorSpanWatcher.kt => EnrichedSpanWatcher.kt} (71%) rename android/src/main/java/com/swmansion/enriched/watchers/{EditorTextWatcher.kt => EnrichedTextWatcher.kt} (55%) diff --git a/android/src/main/java/com/swmansion/enriched/EnrichedTextInputView.kt b/android/src/main/java/com/swmansion/enriched/EnrichedTextInputView.kt index f1601c472..d8a38681a 100644 --- a/android/src/main/java/com/swmansion/enriched/EnrichedTextInputView.kt +++ b/android/src/main/java/com/swmansion/enriched/EnrichedTextInputView.kt @@ -28,25 +28,25 @@ import com.facebook.react.views.text.ReactTypefaceUtils.parseFontWeight import com.swmansion.enriched.events.MentionHandler import com.swmansion.enriched.events.OnInputBlurEvent import com.swmansion.enriched.events.OnInputFocusEvent -import com.swmansion.enriched.spans.EditorSpans +import com.swmansion.enriched.spans.EnrichedSpans import com.swmansion.enriched.styles.InlineStyles import com.swmansion.enriched.styles.ListStyles import com.swmansion.enriched.styles.ParagraphStyles import com.swmansion.enriched.styles.ParametrizedStyles -import com.swmansion.enriched.styles.RichTextStyle -import com.swmansion.enriched.utils.EditorParser -import com.swmansion.enriched.utils.EditorSelection -import com.swmansion.enriched.utils.EditorSpanState +import com.swmansion.enriched.styles.HtmlStyle +import com.swmansion.enriched.utils.EnrichedParser +import com.swmansion.enriched.utils.EnrichedSelection +import com.swmansion.enriched.utils.EnrichedSpanState import com.swmansion.enriched.utils.mergeSpannables -import com.swmansion.enriched.watchers.EditorSpanWatcher -import com.swmansion.enriched.watchers.EditorTextWatcher +import com.swmansion.enriched.watchers.EnrichedSpanWatcher +import com.swmansion.enriched.watchers.EnrichedTextWatcher import kotlin.math.ceil class EnrichedTextInputView : AppCompatEditText { var stateWrapper: StateWrapper? = null - val selection: EditorSelection? = EditorSelection(this) - val spanState: EditorSpanState? = EditorSpanState(this) + val selection: EnrichedSelection? = EnrichedSelection(this) + val spanState: EnrichedSpanState? = EnrichedSpanState(this) val inlineStyles: InlineStyles? = InlineStyles(this) val paragraphStyles: ParagraphStyles? = ParagraphStyles(this) val listStyles: ListStyles? = ListStyles(this) @@ -55,10 +55,9 @@ class EnrichedTextInputView : AppCompatEditText { var isRemovingMany: Boolean = false val mentionHandler: MentionHandler? = MentionHandler(this) - var richTextStyle: RichTextStyle = RichTextStyle(this, null) - var spanWatcher: EditorSpanWatcher? = null - var layoutManager: ReactNativeRichTextEditorViewLayoutManager = - ReactNativeRichTextEditorViewLayoutManager(this) + var htmlStyle: HtmlStyle = HtmlStyle(this, null) + var spanWatcher: EnrichedSpanWatcher? = null + var layoutManager: EnrichedTextInputViewLayoutManager = EnrichedTextInputViewLayoutManager(this) var fontSize: Float? = null private var autoFocus = false @@ -101,8 +100,8 @@ class EnrichedTextInputView : AppCompatEditText { setPadding(0, 0, 0, 0) setBackgroundColor(Color.TRANSPARENT) - addSpanWatcher(EditorSpanWatcher(this)) - addTextChangedListener(EditorTextWatcher(this)) + addSpanWatcher(EnrichedSpanWatcher(this)) + addTextChangedListener(EnrichedTextWatcher(this)) } // https://github.com/facebook/react-native/blob/36df97f500aa0aa8031098caf7526db358b6ddc1/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.kt#L295C1-L296C1 @@ -175,7 +174,7 @@ class EnrichedTextInputView : AppCompatEditText { if (start < end) { val selectedText = spannable.subSequence(start, end) as Spannable - val selectedHtml = EditorParser.toHtml(selectedText) + val selectedHtml = EnrichedParser.toHtml(selectedText) val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager val clip = ClipData.newHtmlText(CLIPBOARD_TAG, selectedText, selectedHtml) @@ -216,7 +215,7 @@ class EnrichedTextInputView : AppCompatEditText { val isHtml = text.startsWith("") && text.endsWith("") if (!isHtml) return text - val parsed = EditorParser.fromHtml(text.toString(), richTextStyle, null) + val parsed = EnrichedParser.fromHtml(text.toString(), htmlStyle, null) val withoutLastNewLine = parsed.trimEnd('\n') return withoutLastNewLine } @@ -229,7 +228,7 @@ class EnrichedTextInputView : AppCompatEditText { setText(newText) // Assign SpanWatcher one more time as our previous spannable has been replaced - addSpanWatcher(EditorSpanWatcher(this)) + addSpanWatcher(EnrichedSpanWatcher(this)) // Scroll to the last line of text setSelection(text?.length ?: 0) @@ -291,7 +290,7 @@ class EnrichedTextInputView : AppCompatEditText { setTextSize(TypedValue.COMPLEX_UNIT_PX, sizeInt) // This ensured that newly created spans will take the new font size into account - richTextStyle.invalidateStyles() + htmlStyle.invalidateStyles() layoutManager.invalidateLayout(text) } @@ -359,19 +358,19 @@ class EnrichedTextInputView : AppCompatEditText { private fun toggleStyle(name: String) { when (name) { - EditorSpans.BOLD -> inlineStyles?.toggleStyle(EditorSpans.BOLD) - EditorSpans.ITALIC -> inlineStyles?.toggleStyle(EditorSpans.ITALIC) - EditorSpans.UNDERLINE -> inlineStyles?.toggleStyle(EditorSpans.UNDERLINE) - EditorSpans.STRIKETHROUGH -> inlineStyles?.toggleStyle(EditorSpans.STRIKETHROUGH) - EditorSpans.INLINE_CODE -> inlineStyles?.toggleStyle(EditorSpans.INLINE_CODE) - EditorSpans.H1 -> paragraphStyles?.toggleStyle(EditorSpans.H1) - EditorSpans.H2 -> paragraphStyles?.toggleStyle(EditorSpans.H2) - EditorSpans.H3 -> paragraphStyles?.toggleStyle(EditorSpans.H3) - EditorSpans.CODE_BLOCK -> paragraphStyles?.toggleStyle(EditorSpans.CODE_BLOCK) - EditorSpans.BLOCK_QUOTE -> paragraphStyles?.toggleStyle(EditorSpans.BLOCK_QUOTE) - EditorSpans.ORDERED_LIST -> listStyles?.toggleStyle(EditorSpans.ORDERED_LIST) - EditorSpans.UNORDERED_LIST -> listStyles?.toggleStyle(EditorSpans.UNORDERED_LIST) - else -> Log.w("ReactNativeRichTextEditorView", "Unknown style: $name") + EnrichedSpans.BOLD -> inlineStyles?.toggleStyle(EnrichedSpans.BOLD) + EnrichedSpans.ITALIC -> inlineStyles?.toggleStyle(EnrichedSpans.ITALIC) + EnrichedSpans.UNDERLINE -> inlineStyles?.toggleStyle(EnrichedSpans.UNDERLINE) + EnrichedSpans.STRIKETHROUGH -> inlineStyles?.toggleStyle(EnrichedSpans.STRIKETHROUGH) + EnrichedSpans.INLINE_CODE -> inlineStyles?.toggleStyle(EnrichedSpans.INLINE_CODE) + EnrichedSpans.H1 -> paragraphStyles?.toggleStyle(EnrichedSpans.H1) + EnrichedSpans.H2 -> paragraphStyles?.toggleStyle(EnrichedSpans.H2) + EnrichedSpans.H3 -> paragraphStyles?.toggleStyle(EnrichedSpans.H3) + EnrichedSpans.CODE_BLOCK -> paragraphStyles?.toggleStyle(EnrichedSpans.CODE_BLOCK) + EnrichedSpans.BLOCK_QUOTE -> paragraphStyles?.toggleStyle(EnrichedSpans.BLOCK_QUOTE) + EnrichedSpans.ORDERED_LIST -> listStyles?.toggleStyle(EnrichedSpans.ORDERED_LIST) + EnrichedSpans.UNORDERED_LIST -> listStyles?.toggleStyle(EnrichedSpans.UNORDERED_LIST) + else -> Log.w("EnrichedTextInputView", "Unknown style: $name") } layoutManager.invalidateLayout(text) @@ -379,21 +378,21 @@ class EnrichedTextInputView : AppCompatEditText { private fun removeStyle(name: String, start: Int, end: Int): Boolean { val removed = when (name) { - EditorSpans.BOLD -> inlineStyles?.removeStyle(EditorSpans.BOLD, start, end) - EditorSpans.ITALIC -> inlineStyles?.removeStyle(EditorSpans.ITALIC, start, end) - EditorSpans.UNDERLINE -> inlineStyles?.removeStyle(EditorSpans.UNDERLINE, start, end) - EditorSpans.STRIKETHROUGH -> inlineStyles?.removeStyle(EditorSpans.STRIKETHROUGH, start, end) - EditorSpans.INLINE_CODE -> inlineStyles?.removeStyle(EditorSpans.INLINE_CODE, start, end) - EditorSpans.H1 -> paragraphStyles?.removeStyle(EditorSpans.H1, start, end) - EditorSpans.H2 -> paragraphStyles?.removeStyle(EditorSpans.H2, start, end) - EditorSpans.H3 -> paragraphStyles?.removeStyle(EditorSpans.H3, start, end) - EditorSpans.CODE_BLOCK -> paragraphStyles?.removeStyle(EditorSpans.CODE_BLOCK, start, end) - EditorSpans.BLOCK_QUOTE -> paragraphStyles?.removeStyle(EditorSpans.BLOCK_QUOTE, start, end) - EditorSpans.ORDERED_LIST -> listStyles?.removeStyle(EditorSpans.ORDERED_LIST, start, end) - EditorSpans.UNORDERED_LIST -> listStyles?.removeStyle(EditorSpans.UNORDERED_LIST, start, end) - EditorSpans.LINK -> parametrizedStyles?.removeStyle(EditorSpans.LINK, start, end) - EditorSpans.IMAGE -> parametrizedStyles?.removeStyle(EditorSpans.IMAGE, start, end) - EditorSpans.MENTION -> parametrizedStyles?.removeStyle(EditorSpans.MENTION, start, end) + EnrichedSpans.BOLD -> inlineStyles?.removeStyle(EnrichedSpans.BOLD, start, end) + EnrichedSpans.ITALIC -> inlineStyles?.removeStyle(EnrichedSpans.ITALIC, start, end) + EnrichedSpans.UNDERLINE -> inlineStyles?.removeStyle(EnrichedSpans.UNDERLINE, start, end) + EnrichedSpans.STRIKETHROUGH -> inlineStyles?.removeStyle(EnrichedSpans.STRIKETHROUGH, start, end) + EnrichedSpans.INLINE_CODE -> inlineStyles?.removeStyle(EnrichedSpans.INLINE_CODE, start, end) + EnrichedSpans.H1 -> paragraphStyles?.removeStyle(EnrichedSpans.H1, start, end) + EnrichedSpans.H2 -> paragraphStyles?.removeStyle(EnrichedSpans.H2, start, end) + EnrichedSpans.H3 -> paragraphStyles?.removeStyle(EnrichedSpans.H3, start, end) + EnrichedSpans.CODE_BLOCK -> paragraphStyles?.removeStyle(EnrichedSpans.CODE_BLOCK, start, end) + EnrichedSpans.BLOCK_QUOTE -> paragraphStyles?.removeStyle(EnrichedSpans.BLOCK_QUOTE, start, end) + EnrichedSpans.ORDERED_LIST -> listStyles?.removeStyle(EnrichedSpans.ORDERED_LIST, start, end) + EnrichedSpans.UNORDERED_LIST -> listStyles?.removeStyle(EnrichedSpans.UNORDERED_LIST, start, end) + EnrichedSpans.LINK -> parametrizedStyles?.removeStyle(EnrichedSpans.LINK, start, end) + EnrichedSpans.IMAGE -> parametrizedStyles?.removeStyle(EnrichedSpans.IMAGE, start, end) + EnrichedSpans.MENTION -> parametrizedStyles?.removeStyle(EnrichedSpans.MENTION, start, end) else -> false } @@ -402,21 +401,21 @@ class EnrichedTextInputView : AppCompatEditText { private fun getTargetRange(name: String): Pair { val result = when (name) { - EditorSpans.BOLD -> inlineStyles?.getStyleRange() - EditorSpans.ITALIC -> inlineStyles?.getStyleRange() - EditorSpans.UNDERLINE -> inlineStyles?.getStyleRange() - EditorSpans.STRIKETHROUGH -> inlineStyles?.getStyleRange() - EditorSpans.INLINE_CODE -> inlineStyles?.getStyleRange() - EditorSpans.H1 -> paragraphStyles?.getStyleRange() - EditorSpans.H2 -> paragraphStyles?.getStyleRange() - EditorSpans.H3 -> paragraphStyles?.getStyleRange() - EditorSpans.CODE_BLOCK -> paragraphStyles?.getStyleRange() - EditorSpans.BLOCK_QUOTE -> paragraphStyles?.getStyleRange() - EditorSpans.ORDERED_LIST -> listStyles?.getStyleRange() - EditorSpans.UNORDERED_LIST -> listStyles?.getStyleRange() - EditorSpans.LINK -> parametrizedStyles?.getStyleRange() - EditorSpans.IMAGE -> parametrizedStyles?.getStyleRange() - EditorSpans.MENTION -> parametrizedStyles?.getStyleRange() + EnrichedSpans.BOLD -> inlineStyles?.getStyleRange() + EnrichedSpans.ITALIC -> inlineStyles?.getStyleRange() + EnrichedSpans.UNDERLINE -> inlineStyles?.getStyleRange() + EnrichedSpans.STRIKETHROUGH -> inlineStyles?.getStyleRange() + EnrichedSpans.INLINE_CODE -> inlineStyles?.getStyleRange() + EnrichedSpans.H1 -> paragraphStyles?.getStyleRange() + EnrichedSpans.H2 -> paragraphStyles?.getStyleRange() + EnrichedSpans.H3 -> paragraphStyles?.getStyleRange() + EnrichedSpans.CODE_BLOCK -> paragraphStyles?.getStyleRange() + EnrichedSpans.BLOCK_QUOTE -> paragraphStyles?.getStyleRange() + EnrichedSpans.ORDERED_LIST -> listStyles?.getStyleRange() + EnrichedSpans.UNORDERED_LIST -> listStyles?.getStyleRange() + EnrichedSpans.LINK -> parametrizedStyles?.getStyleRange() + EnrichedSpans.IMAGE -> parametrizedStyles?.getStyleRange() + EnrichedSpans.MENTION -> parametrizedStyles?.getStyleRange() else -> Pair(0, 0) } @@ -424,7 +423,7 @@ class EnrichedTextInputView : AppCompatEditText { } private fun verifyStyle(name: String): Boolean { - val mergingConfig = EditorSpans.mergingConfig[name] ?: return true + val mergingConfig = EnrichedSpans.mergingConfig[name] ?: return true val conflictingStyles = mergingConfig.conflictingStyles val blockingStyles = mergingConfig.blockingStyles val isEnabling = spanState?.getStart(name) == null @@ -465,7 +464,7 @@ class EnrichedTextInputView : AppCompatEditText { return true } - private fun addSpanWatcher(watcher: EditorSpanWatcher) { + private fun addSpanWatcher(watcher: EnrichedSpanWatcher) { val spannable = text as Spannable spannable.setSpan(watcher, 0, spannable.length, Spannable.SPAN_INCLUSIVE_INCLUSIVE) spanWatcher = watcher @@ -479,28 +478,28 @@ class EnrichedTextInputView : AppCompatEditText { } fun addLink(start: Int, end: Int, text: String, url: String) { - val isValid = verifyStyle(EditorSpans.LINK) + val isValid = verifyStyle(EnrichedSpans.LINK) if (!isValid) return parametrizedStyles?.setLinkSpan(start, end, text, url) } fun addImage(src: String) { - val isValid = verifyStyle(EditorSpans.IMAGE) + val isValid = verifyStyle(EnrichedSpans.IMAGE) if (!isValid) return parametrizedStyles?.setImageSpan(src) } fun startMention(indicator: String) { - val isValid = verifyStyle(EditorSpans.MENTION) + val isValid = verifyStyle(EnrichedSpans.MENTION) if (!isValid) return parametrizedStyles?.startMention(indicator) } fun addMention(indicator: String, text: String, attributes: Map) { - val isValid = verifyStyle(EditorSpans.MENTION) + val isValid = verifyStyle(EnrichedSpans.MENTION) if (!isValid) return parametrizedStyles?.setMentionSpan(text, indicator, attributes) @@ -522,6 +521,6 @@ class EnrichedTextInputView : AppCompatEditText { } companion object { - const val CLIPBOARD_TAG = "react-native-rich-text-editor-clipboard" + const val CLIPBOARD_TAG = "react-native-enriched-clipboard" } } diff --git a/android/src/main/java/com/swmansion/enriched/ReactNativeRichTextEditorViewLayoutManager.kt b/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewLayoutManager.kt similarity index 88% rename from android/src/main/java/com/swmansion/enriched/ReactNativeRichTextEditorViewLayoutManager.kt rename to android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewLayoutManager.kt index 53768959f..3077b92c5 100644 --- a/android/src/main/java/com/swmansion/enriched/ReactNativeRichTextEditorViewLayoutManager.kt +++ b/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewLayoutManager.kt @@ -5,7 +5,7 @@ import android.text.StaticLayout import com.facebook.react.bridge.Arguments import com.facebook.react.uimanager.PixelUtil -class ReactNativeRichTextEditorViewLayoutManager(private val editorView: EnrichedTextInputView) { +class EnrichedTextInputViewLayoutManager(private val view: EnrichedTextInputView) { private var cachedSize: Pair = Pair(0f, 0f) private var cachedYogaWidth: Float = 0f private var forceHeightRecalculationCounter: Int = 0 @@ -22,7 +22,7 @@ class ReactNativeRichTextEditorViewLayoutManager(private val editorView: Enriche forceHeightRecalculationCounter++ val state = Arguments.createMap() state.putInt("forceHeightRecalculationCounter", counter) - editorView.stateWrapper?.updateState(state) + view.stateWrapper?.updateState(state) } fun getMeasuredSize(maxWidth: Float): Pair { @@ -30,7 +30,7 @@ class ReactNativeRichTextEditorViewLayoutManager(private val editorView: Enriche return cachedSize } - val text = editorView.text ?: "" + val text = view.text ?: "" val result = measureAndCacheSize(text, maxWidth) cachedYogaWidth = maxWidth return result @@ -47,7 +47,7 @@ class ReactNativeRichTextEditorViewLayoutManager(private val editorView: Enriche } private fun measureSize(text: CharSequence, maxWidth: Float): Pair { - val paint = editorView.paint + val paint = view.paint val textLength = text.length val staticLayout = StaticLayout.Builder diff --git a/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewManager.kt b/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewManager.kt index 41fcef382..5ef32d673 100644 --- a/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewManager.kt +++ b/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewManager.kt @@ -25,8 +25,8 @@ import com.swmansion.enriched.events.OnInputFocusEvent import com.swmansion.enriched.events.OnLinkDetectedEvent import com.swmansion.enriched.events.OnMentionDetectedEvent import com.swmansion.enriched.events.OnMentionEvent -import com.swmansion.enriched.spans.EditorSpans -import com.swmansion.enriched.styles.RichTextStyle +import com.swmansion.enriched.spans.EnrichedSpans +import com.swmansion.enriched.styles.HtmlStyle import com.swmansion.enriched.utils.jsonStringToStringMap @ReactModule(name = EnrichedTextInputViewManager.NAME) @@ -127,9 +127,9 @@ class EnrichedTextInputViewManager : SimpleViewManager(), view?.parametrizedStyles?.mentionIndicators = indicatorsArray } - @ReactProp(name = "richTextStyle") + @ReactProp(name = "htmlStyle") override fun setHtmlStyle(view: EnrichedTextInputView?, style: ReadableMap?) { - view?.richTextStyle = RichTextStyle(view, style) + view?.htmlStyle = HtmlStyle(view, style) } @ReactProp(name = ViewProps.COLOR, customType = "Color") @@ -195,51 +195,51 @@ class EnrichedTextInputViewManager : SimpleViewManager(), } override fun toggleBold(view: EnrichedTextInputView?) { - view?.verifyAndToggleStyle(EditorSpans.BOLD) + view?.verifyAndToggleStyle(EnrichedSpans.BOLD) } override fun toggleItalic(view: EnrichedTextInputView?) { - view?.verifyAndToggleStyle(EditorSpans.ITALIC) + view?.verifyAndToggleStyle(EnrichedSpans.ITALIC) } override fun toggleUnderline(view: EnrichedTextInputView?) { - view?.verifyAndToggleStyle(EditorSpans.UNDERLINE) + view?.verifyAndToggleStyle(EnrichedSpans.UNDERLINE) } override fun toggleStrikeThrough(view: EnrichedTextInputView?) { - view?.verifyAndToggleStyle(EditorSpans.STRIKETHROUGH) + view?.verifyAndToggleStyle(EnrichedSpans.STRIKETHROUGH) } override fun toggleInlineCode(view: EnrichedTextInputView?) { - view?.verifyAndToggleStyle(EditorSpans.INLINE_CODE) + view?.verifyAndToggleStyle(EnrichedSpans.INLINE_CODE) } override fun toggleH1(view: EnrichedTextInputView?) { - view?.verifyAndToggleStyle(EditorSpans.H1) + view?.verifyAndToggleStyle(EnrichedSpans.H1) } override fun toggleH2(view: EnrichedTextInputView?) { - view?.verifyAndToggleStyle(EditorSpans.H2) + view?.verifyAndToggleStyle(EnrichedSpans.H2) } override fun toggleH3(view: EnrichedTextInputView?) { - view?.verifyAndToggleStyle(EditorSpans.H3) + view?.verifyAndToggleStyle(EnrichedSpans.H3) } override fun toggleCodeBlock(view: EnrichedTextInputView?) { - view?.verifyAndToggleStyle(EditorSpans.CODE_BLOCK) + view?.verifyAndToggleStyle(EnrichedSpans.CODE_BLOCK) } override fun toggleBlockQuote(view: EnrichedTextInputView?) { - view?.verifyAndToggleStyle(EditorSpans.BLOCK_QUOTE) + view?.verifyAndToggleStyle(EnrichedSpans.BLOCK_QUOTE) } override fun toggleOrderedList(view: EnrichedTextInputView?) { - view?.verifyAndToggleStyle(EditorSpans.ORDERED_LIST) + view?.verifyAndToggleStyle(EnrichedSpans.ORDERED_LIST) } override fun toggleUnorderedList(view: EnrichedTextInputView?) { - view?.verifyAndToggleStyle(EditorSpans.UNORDERED_LIST) + view?.verifyAndToggleStyle(EnrichedSpans.UNORDERED_LIST) } override fun addLink(view: EnrichedTextInputView?, start: Int, end: Int, text: String, url: String) { diff --git a/android/src/main/java/com/swmansion/enriched/ReactNativeRichTextEditorPackage.kt b/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewPackage.kt similarity index 100% rename from android/src/main/java/com/swmansion/enriched/ReactNativeRichTextEditorPackage.kt rename to android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewPackage.kt diff --git a/android/src/main/java/com/swmansion/enriched/events/MentionHandler.kt b/android/src/main/java/com/swmansion/enriched/events/MentionHandler.kt index 53da0a5b8..b73da8172 100644 --- a/android/src/main/java/com/swmansion/enriched/events/MentionHandler.kt +++ b/android/src/main/java/com/swmansion/enriched/events/MentionHandler.kt @@ -4,7 +4,7 @@ import com.facebook.react.bridge.ReactContext import com.facebook.react.uimanager.UIManagerHelper import com.swmansion.enriched.EnrichedTextInputView -class MentionHandler(private val editorView: EnrichedTextInputView) { +class MentionHandler(private val view: EnrichedTextInputView) { private var previousText: String? = null private var previousIndicator: String? = null @@ -26,9 +26,9 @@ class MentionHandler(private val editorView: EnrichedTextInputView) { if (previousText == text) return previousText = text - val context = editorView.context as ReactContext + val context = view.context as ReactContext val surfaceId = UIManagerHelper.getSurfaceId(context) - val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, editorView.id) - dispatcher?.dispatchEvent(OnMentionEvent(surfaceId, editorView.id, indicator, text)) + val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, view.id) + dispatcher?.dispatchEvent(OnMentionEvent(surfaceId, view.id, indicator, text)) } } diff --git a/android/src/main/java/com/swmansion/enriched/spans/EditorBoldSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EditorBoldSpan.kt deleted file mode 100644 index f16e67663..000000000 --- a/android/src/main/java/com/swmansion/enriched/spans/EditorBoldSpan.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.swmansion.enriched.spans - -import android.graphics.Typeface -import android.text.style.StyleSpan -import com.swmansion.enriched.spans.interfaces.EditorInlineSpan -import com.swmansion.enriched.styles.RichTextStyle - -@Suppress("UNUSED_PARAMETER") -class EditorBoldSpan(private val richTextStyle: RichTextStyle) : StyleSpan(Typeface.BOLD), EditorInlineSpan { -} diff --git a/android/src/main/java/com/swmansion/enriched/spans/EditorItalicSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EditorItalicSpan.kt deleted file mode 100644 index 8f52765a7..000000000 --- a/android/src/main/java/com/swmansion/enriched/spans/EditorItalicSpan.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.swmansion.enriched.spans - -import android.graphics.Typeface -import android.text.style.StyleSpan -import com.swmansion.enriched.spans.interfaces.EditorInlineSpan -import com.swmansion.enriched.styles.RichTextStyle - -@Suppress("UNUSED_PARAMETER") -class EditorItalicSpan(private val richTextStyle: RichTextStyle) : StyleSpan(Typeface.ITALIC), EditorInlineSpan { -} diff --git a/android/src/main/java/com/swmansion/enriched/spans/EditorLinkSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EditorLinkSpan.kt deleted file mode 100644 index 775cd768f..000000000 --- a/android/src/main/java/com/swmansion/enriched/spans/EditorLinkSpan.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.swmansion.enriched.spans - -import android.text.TextPaint -import android.text.style.ClickableSpan -import android.view.View -import com.swmansion.enriched.spans.interfaces.EditorInlineSpan -import com.swmansion.enriched.styles.RichTextStyle - -class EditorLinkSpan(private val url: String, private val richTextStyle: RichTextStyle) : ClickableSpan(), EditorInlineSpan { - override fun onClick(view: View) { - // Do nothing, links inside the editor are not clickable. - // We are using `ClickableSpan` to allow the text to be styled as a link. - } - - override fun updateDrawState(textPaint: TextPaint) { - super.updateDrawState(textPaint) - textPaint.color = richTextStyle.aColor - textPaint.isUnderlineText = richTextStyle.aUnderline - } - - fun getUrl(): String { - return url - } -} diff --git a/android/src/main/java/com/swmansion/enriched/spans/EditorStrikeThroughSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EditorStrikeThroughSpan.kt deleted file mode 100644 index ff761e5b4..000000000 --- a/android/src/main/java/com/swmansion/enriched/spans/EditorStrikeThroughSpan.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.swmansion.enriched.spans - -import android.text.style.StrikethroughSpan -import com.swmansion.enriched.spans.interfaces.EditorInlineSpan -import com.swmansion.enriched.styles.RichTextStyle - -@Suppress("UNUSED_PARAMETER") -class EditorStrikeThroughSpan(private val richTextStyle: RichTextStyle) : StrikethroughSpan(), EditorInlineSpan { -} diff --git a/android/src/main/java/com/swmansion/enriched/spans/EditorUnderlineSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EditorUnderlineSpan.kt deleted file mode 100644 index 52475aca3..000000000 --- a/android/src/main/java/com/swmansion/enriched/spans/EditorUnderlineSpan.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.swmansion.enriched.spans - -import android.text.style.UnderlineSpan -import com.swmansion.enriched.spans.interfaces.EditorInlineSpan -import com.swmansion.enriched.styles.RichTextStyle - -@Suppress("UNUSED_PARAMETER") -class EditorUnderlineSpan(private val richTextStyle: RichTextStyle) : UnderlineSpan(), EditorInlineSpan { -} diff --git a/android/src/main/java/com/swmansion/enriched/spans/EditorBlockQuoteSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EnrichedBlockQuoteSpan.kt similarity index 61% rename from android/src/main/java/com/swmansion/enriched/spans/EditorBlockQuoteSpan.kt rename to android/src/main/java/com/swmansion/enriched/spans/EnrichedBlockQuoteSpan.kt index 5f26334e5..4e75e2968 100644 --- a/android/src/main/java/com/swmansion/enriched/spans/EditorBlockQuoteSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EnrichedBlockQuoteSpan.kt @@ -6,27 +6,27 @@ import android.text.Layout import android.text.TextPaint import android.text.style.CharacterStyle import android.text.style.LeadingMarginSpan -import com.swmansion.enriched.spans.interfaces.EditorBlockSpan -import com.swmansion.enriched.styles.RichTextStyle +import com.swmansion.enriched.spans.interfaces.EnrichedBlockSpan +import com.swmansion.enriched.styles.HtmlStyle // https://android.googlesource.com/platform/frameworks/base/+/refs/heads/main/core/java/android/text/style/QuoteSpan.java -class EditorBlockQuoteSpan(private val richTextStyle: RichTextStyle) : CharacterStyle(), LeadingMarginSpan, EditorBlockSpan { +class EnrichedBlockQuoteSpan(private val htmlStyle: HtmlStyle) : CharacterStyle(), LeadingMarginSpan, EnrichedBlockSpan { override fun getLeadingMargin(p0: Boolean): Int { - return richTextStyle.blockquoteStripeWidth + richTextStyle.blockquoteGapWidth + return htmlStyle.blockquoteStripeWidth + htmlStyle.blockquoteGapWidth } override fun drawLeadingMargin(c: Canvas, p: Paint, x: Int, dir: Int, top: Int, baseline: Int, bottom: Int, text: CharSequence?, start: Int, end: Int, first: Boolean, layout: Layout?) { val style = p.style val color = p.color p.style = Paint.Style.FILL - p.color = richTextStyle.blockquoteBorderColor - c.drawRect(x.toFloat(), top.toFloat(), x + dir * richTextStyle.blockquoteStripeWidth.toFloat(), bottom.toFloat(), p) + p.color = htmlStyle.blockquoteBorderColor + c.drawRect(x.toFloat(), top.toFloat(), x + dir * htmlStyle.blockquoteStripeWidth.toFloat(), bottom.toFloat(), p) p.style = style p.color = color } override fun updateDrawState(textPaint: TextPaint?) { - val color = richTextStyle.blockquoteColor + val color = htmlStyle.blockquoteColor if (color != null) { textPaint?.color = color } diff --git a/android/src/main/java/com/swmansion/enriched/spans/EnrichedBoldSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EnrichedBoldSpan.kt new file mode 100644 index 000000000..72a5d4e7a --- /dev/null +++ b/android/src/main/java/com/swmansion/enriched/spans/EnrichedBoldSpan.kt @@ -0,0 +1,10 @@ +package com.swmansion.enriched.spans + +import android.graphics.Typeface +import android.text.style.StyleSpan +import com.swmansion.enriched.spans.interfaces.EnrichedInlineSpan +import com.swmansion.enriched.styles.HtmlStyle + +@Suppress("UNUSED_PARAMETER") +class EnrichedBoldSpan(htmlStyle: HtmlStyle) : StyleSpan(Typeface.BOLD), EnrichedInlineSpan { +} diff --git a/android/src/main/java/com/swmansion/enriched/spans/EditorCodeBlockSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EnrichedCodeBlockSpan.kt similarity index 63% rename from android/src/main/java/com/swmansion/enriched/spans/EditorCodeBlockSpan.kt rename to android/src/main/java/com/swmansion/enriched/spans/EnrichedCodeBlockSpan.kt index bf55eda5d..2cca7ce60 100644 --- a/android/src/main/java/com/swmansion/enriched/spans/EditorCodeBlockSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EnrichedCodeBlockSpan.kt @@ -7,13 +7,13 @@ import android.graphics.Typeface import android.text.TextPaint import android.text.style.CharacterStyle import android.text.style.LineBackgroundSpan -import com.swmansion.enriched.spans.interfaces.EditorBlockSpan -import com.swmansion.enriched.styles.RichTextStyle +import com.swmansion.enriched.spans.interfaces.EnrichedBlockSpan +import com.swmansion.enriched.styles.HtmlStyle -class EditorCodeBlockSpan(private val richTextStyle: RichTextStyle) : CharacterStyle(), LineBackgroundSpan, EditorBlockSpan { +class EnrichedCodeBlockSpan(private val htmlStyle: HtmlStyle) : CharacterStyle(), LineBackgroundSpan, EnrichedBlockSpan { override fun updateDrawState(paint: TextPaint?) { paint?.typeface = Typeface.MONOSPACE - paint?.color = richTextStyle.codeBlockColor + paint?.color = htmlStyle.codeBlockColor } override fun drawBackground( @@ -30,9 +30,9 @@ class EditorCodeBlockSpan(private val richTextStyle: RichTextStyle) : CharacterS lineNum: Int ) { val previousColor = p.color - p.color = richTextStyle.codeBlockBackgroundColor + p.color = htmlStyle.codeBlockBackgroundColor val rect = RectF(left.toFloat(), top.toFloat(), right.toFloat(), bottom.toFloat()) - canvas.drawRoundRect(rect, richTextStyle.codeBlockRadius, richTextStyle.codeBlockRadius, p) + canvas.drawRoundRect(rect, htmlStyle.codeBlockRadius, htmlStyle.codeBlockRadius, p) p.color = previousColor } } diff --git a/android/src/main/java/com/swmansion/enriched/spans/EditorH1Span.kt b/android/src/main/java/com/swmansion/enriched/spans/EnrichedH1Span.kt similarity index 60% rename from android/src/main/java/com/swmansion/enriched/spans/EditorH1Span.kt rename to android/src/main/java/com/swmansion/enriched/spans/EnrichedH1Span.kt index 3810bc397..c2b28e3f3 100644 --- a/android/src/main/java/com/swmansion/enriched/spans/EditorH1Span.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EnrichedH1Span.kt @@ -3,10 +3,10 @@ package com.swmansion.enriched.spans import android.graphics.Typeface import android.text.TextPaint import android.text.style.AbsoluteSizeSpan -import com.swmansion.enriched.spans.interfaces.EditorHeadingSpan -import com.swmansion.enriched.styles.RichTextStyle +import com.swmansion.enriched.spans.interfaces.EnrichedHeadingSpan +import com.swmansion.enriched.styles.HtmlStyle -class EditorH1Span(private val style: RichTextStyle) : AbsoluteSizeSpan(style.h1FontSize), EditorHeadingSpan { +class EnrichedH1Span(private val style: HtmlStyle) : AbsoluteSizeSpan(style.h1FontSize), EnrichedHeadingSpan { override fun updateDrawState(tp: TextPaint) { super.updateDrawState(tp) val bold = style.h1Bold diff --git a/android/src/main/java/com/swmansion/enriched/spans/EditorH2Span.kt b/android/src/main/java/com/swmansion/enriched/spans/EnrichedH2Span.kt similarity index 53% rename from android/src/main/java/com/swmansion/enriched/spans/EditorH2Span.kt rename to android/src/main/java/com/swmansion/enriched/spans/EnrichedH2Span.kt index e015aef5c..736fe08cd 100644 --- a/android/src/main/java/com/swmansion/enriched/spans/EditorH2Span.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EnrichedH2Span.kt @@ -3,13 +3,13 @@ package com.swmansion.enriched.spans import android.graphics.Typeface import android.text.TextPaint import android.text.style.AbsoluteSizeSpan -import com.swmansion.enriched.spans.interfaces.EditorHeadingSpan -import com.swmansion.enriched.styles.RichTextStyle +import com.swmansion.enriched.spans.interfaces.EnrichedHeadingSpan +import com.swmansion.enriched.styles.HtmlStyle -class EditorH2Span(private val richTextStyle: RichTextStyle) : AbsoluteSizeSpan(richTextStyle.h2FontSize), EditorHeadingSpan { +class EnrichedH2Span(private val htmlStyle: HtmlStyle) : AbsoluteSizeSpan(htmlStyle.h2FontSize), EnrichedHeadingSpan { override fun updateDrawState(tp: TextPaint) { super.updateDrawState(tp) - val bold = richTextStyle.h2Bold + val bold = htmlStyle.h2Bold if (bold) { tp.typeface = Typeface.create(tp.typeface, Typeface.BOLD) } diff --git a/android/src/main/java/com/swmansion/enriched/spans/EditorH3Span.kt b/android/src/main/java/com/swmansion/enriched/spans/EnrichedH3Span.kt similarity index 53% rename from android/src/main/java/com/swmansion/enriched/spans/EditorH3Span.kt rename to android/src/main/java/com/swmansion/enriched/spans/EnrichedH3Span.kt index 99351553e..151acf656 100644 --- a/android/src/main/java/com/swmansion/enriched/spans/EditorH3Span.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EnrichedH3Span.kt @@ -3,13 +3,13 @@ package com.swmansion.enriched.spans import android.graphics.Typeface import android.text.TextPaint import android.text.style.AbsoluteSizeSpan -import com.swmansion.enriched.spans.interfaces.EditorHeadingSpan -import com.swmansion.enriched.styles.RichTextStyle +import com.swmansion.enriched.spans.interfaces.EnrichedHeadingSpan +import com.swmansion.enriched.styles.HtmlStyle -class EditorH3Span(private val richTextStyle: RichTextStyle) : AbsoluteSizeSpan(richTextStyle.h3FontSize), EditorHeadingSpan { +class EnrichedH3Span(private val htmlStyle: HtmlStyle) : AbsoluteSizeSpan(htmlStyle.h3FontSize), EnrichedHeadingSpan { override fun updateDrawState(tp: TextPaint) { super.updateDrawState(tp) - val bold = richTextStyle.h3Bold + val bold = htmlStyle.h3Bold if (bold) { tp.typeface = Typeface.create(tp.typeface, Typeface.BOLD) } diff --git a/android/src/main/java/com/swmansion/enriched/spans/EditorImageSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EnrichedImageSpan.kt similarity index 54% rename from android/src/main/java/com/swmansion/enriched/spans/EditorImageSpan.kt rename to android/src/main/java/com/swmansion/enriched/spans/EnrichedImageSpan.kt index 265411323..708050d62 100644 --- a/android/src/main/java/com/swmansion/enriched/spans/EditorImageSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EnrichedImageSpan.kt @@ -7,18 +7,18 @@ import android.graphics.drawable.Drawable import android.net.Uri import android.text.style.ImageSpan import androidx.core.graphics.withSave -import com.swmansion.enriched.spans.interfaces.EditorInlineSpan -import com.swmansion.enriched.styles.RichTextStyle +import com.swmansion.enriched.spans.interfaces.EnrichedInlineSpan +import com.swmansion.enriched.styles.HtmlStyle -class EditorImageSpan : ImageSpan, EditorInlineSpan { - private var richTextStyle: RichTextStyle? = null +class EnrichedImageSpan : ImageSpan, EnrichedInlineSpan { + private var htmlStyle: HtmlStyle? = null - constructor(context: Context, uri: Uri, richTextStyle: RichTextStyle, ) : super(context, uri, ALIGN_BASELINE) { - this.richTextStyle = richTextStyle + constructor(context: Context, uri: Uri, htmlStyle: HtmlStyle, ) : super(context, uri, ALIGN_BASELINE) { + this.htmlStyle = htmlStyle } - constructor(drawable: Drawable, source: String, richTextStyle: RichTextStyle) : super(drawable, source, ALIGN_BASELINE) { - this.richTextStyle = richTextStyle + constructor(drawable: Drawable, source: String, htmlStyle: HtmlStyle) : super(drawable, source, ALIGN_BASELINE) { + this.htmlStyle = htmlStyle } override fun draw( @@ -35,7 +35,7 @@ class EditorImageSpan : ImageSpan, EditorInlineSpan { override fun getDrawable(): Drawable { val drawable = super.getDrawable() - drawable.setBounds(0, 0, richTextStyle!!.imgWidth, richTextStyle!!.imgHeight) + drawable.setBounds(0, 0, htmlStyle!!.imgWidth, htmlStyle!!.imgHeight) return drawable } } diff --git a/android/src/main/java/com/swmansion/enriched/spans/EditorInlineCodeSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EnrichedInlineCodeSpan.kt similarity index 50% rename from android/src/main/java/com/swmansion/enriched/spans/EditorInlineCodeSpan.kt rename to android/src/main/java/com/swmansion/enriched/spans/EnrichedInlineCodeSpan.kt index 2ecf09390..90d6b8ffe 100644 --- a/android/src/main/java/com/swmansion/enriched/spans/EditorInlineCodeSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EnrichedInlineCodeSpan.kt @@ -3,14 +3,14 @@ package com.swmansion.enriched.spans import android.graphics.Typeface import android.text.TextPaint import android.text.style.BackgroundColorSpan -import com.swmansion.enriched.spans.interfaces.EditorInlineSpan -import com.swmansion.enriched.styles.RichTextStyle +import com.swmansion.enriched.spans.interfaces.EnrichedInlineSpan +import com.swmansion.enriched.styles.HtmlStyle -class EditorInlineCodeSpan(private val richTextStyle: RichTextStyle) : BackgroundColorSpan(richTextStyle.inlineCodeBackgroundColor), EditorInlineSpan { +class EnrichedInlineCodeSpan(private val htmlStyle: HtmlStyle) : BackgroundColorSpan(htmlStyle.inlineCodeBackgroundColor), EnrichedInlineSpan { override fun updateDrawState(textPaint: TextPaint) { super.updateDrawState(textPaint) - textPaint.color = richTextStyle.inlineCodeColor + textPaint.color = htmlStyle.inlineCodeColor textPaint.typeface = Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL) } } diff --git a/android/src/main/java/com/swmansion/enriched/spans/EnrichedItalicSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EnrichedItalicSpan.kt new file mode 100644 index 000000000..3d44f9e91 --- /dev/null +++ b/android/src/main/java/com/swmansion/enriched/spans/EnrichedItalicSpan.kt @@ -0,0 +1,10 @@ +package com.swmansion.enriched.spans + +import android.graphics.Typeface +import android.text.style.StyleSpan +import com.swmansion.enriched.spans.interfaces.EnrichedInlineSpan +import com.swmansion.enriched.styles.HtmlStyle + +@Suppress("UNUSED_PARAMETER") +class EnrichedItalicSpan(private val htmlStyle: HtmlStyle) : StyleSpan(Typeface.ITALIC), EnrichedInlineSpan { +} diff --git a/android/src/main/java/com/swmansion/enriched/spans/EnrichedLinkSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EnrichedLinkSpan.kt new file mode 100644 index 000000000..b8a96369c --- /dev/null +++ b/android/src/main/java/com/swmansion/enriched/spans/EnrichedLinkSpan.kt @@ -0,0 +1,24 @@ +package com.swmansion.enriched.spans + +import android.text.TextPaint +import android.text.style.ClickableSpan +import android.view.View +import com.swmansion.enriched.spans.interfaces.EnrichedInlineSpan +import com.swmansion.enriched.styles.HtmlStyle + +class EnrichedLinkSpan(private val url: String, private val htmlStyle: HtmlStyle) : ClickableSpan(), EnrichedInlineSpan { + override fun onClick(view: View) { + // Do nothing, links inside the input are not clickable. + // We are using `ClickableSpan` to allow the text to be styled as a link. + } + + override fun updateDrawState(textPaint: TextPaint) { + super.updateDrawState(textPaint) + textPaint.color = htmlStyle.aColor + textPaint.isUnderlineText = htmlStyle.aUnderline + } + + fun getUrl(): String { + return url + } +} diff --git a/android/src/main/java/com/swmansion/enriched/spans/EditorMentionSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EnrichedMentionSpan.kt similarity index 60% rename from android/src/main/java/com/swmansion/enriched/spans/EditorMentionSpan.kt rename to android/src/main/java/com/swmansion/enriched/spans/EnrichedMentionSpan.kt index bc9ca51ed..f28925b5c 100644 --- a/android/src/main/java/com/swmansion/enriched/spans/EditorMentionSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EnrichedMentionSpan.kt @@ -3,20 +3,20 @@ package com.swmansion.enriched.spans import android.text.TextPaint import android.text.style.ClickableSpan import android.view.View -import com.swmansion.enriched.spans.interfaces.EditorInlineSpan -import com.swmansion.enriched.styles.RichTextStyle +import com.swmansion.enriched.spans.interfaces.EnrichedInlineSpan +import com.swmansion.enriched.styles.HtmlStyle -class EditorMentionSpan(private val text: String, private val indicator: String, private val attributes: Map, private val richTextStyle: RichTextStyle) : - ClickableSpan(), EditorInlineSpan { +class EnrichedMentionSpan(private val text: String, private val indicator: String, private val attributes: Map, private val htmlStyle: HtmlStyle) : + ClickableSpan(), EnrichedInlineSpan { override fun onClick(view: View) { - // Do nothing. Mentions inside the editor are not clickable. + // Do nothing. Mentions inside the input are not clickable. // We are using `ClickableSpan` to allow the text to be styled as a clickable element. } override fun updateDrawState(textPaint: TextPaint) { super.updateDrawState(textPaint) - val mentionsStyle = richTextStyle.mentionsStyle[indicator] ?: return + val mentionsStyle = htmlStyle.mentionsStyle[indicator] ?: return textPaint.color = mentionsStyle.color textPaint.bgColor = mentionsStyle.backgroundColor textPaint.isUnderlineText = mentionsStyle.underline diff --git a/android/src/main/java/com/swmansion/enriched/spans/EditorOrderedListSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EnrichedOrderedListSpan.kt similarity index 73% rename from android/src/main/java/com/swmansion/enriched/spans/EditorOrderedListSpan.kt rename to android/src/main/java/com/swmansion/enriched/spans/EnrichedOrderedListSpan.kt index 18824ff85..e0f2242d0 100644 --- a/android/src/main/java/com/swmansion/enriched/spans/EditorOrderedListSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EnrichedOrderedListSpan.kt @@ -5,12 +5,12 @@ import android.graphics.Paint import android.graphics.Typeface import android.text.Layout import android.text.style.LeadingMarginSpan -import com.swmansion.enriched.spans.interfaces.EditorParagraphSpan -import com.swmansion.enriched.styles.RichTextStyle +import com.swmansion.enriched.spans.interfaces.EnrichedParagraphSpan +import com.swmansion.enriched.styles.HtmlStyle -class EditorOrderedListSpan(private var index: Int, private val richTextStyle: RichTextStyle) : LeadingMarginSpan, EditorParagraphSpan { +class EnrichedOrderedListSpan(private var index: Int, private val htmlStyle: HtmlStyle) : LeadingMarginSpan, EnrichedParagraphSpan { override fun getLeadingMargin(first: Boolean): Int { - return richTextStyle.olMarginLeft + richTextStyle.olGapWidth + return htmlStyle.olMarginLeft + htmlStyle.olGapWidth } override fun drawLeadingMargin( @@ -32,13 +32,13 @@ class EditorOrderedListSpan(private var index: Int, private val richTextStyle: R val width = paint.measureText(text) val yPosition = baseline.toFloat() - val xPosition = (richTextStyle.olMarginLeft + x - width / 2) * dir + val xPosition = (htmlStyle.olMarginLeft + x - width / 2) * dir val originalColor = paint.color val originalTypeface = paint.typeface - paint.color = richTextStyle.olMarkerColor ?: originalColor - paint.typeface = getTypeface(richTextStyle.olMarkerFontWeight, originalTypeface) + paint.color = htmlStyle.olMarkerColor ?: originalColor + paint.typeface = getTypeface(htmlStyle.olMarkerFontWeight, originalTypeface) canvas.drawText(text, xPosition, yPosition, paint) paint.color = originalColor diff --git a/android/src/main/java/com/swmansion/enriched/spans/EditorSpans.kt b/android/src/main/java/com/swmansion/enriched/spans/EnrichedSpans.kt similarity index 75% rename from android/src/main/java/com/swmansion/enriched/spans/EditorSpans.kt rename to android/src/main/java/com/swmansion/enriched/spans/EnrichedSpans.kt index 2e41364aa..85e47b28c 100644 --- a/android/src/main/java/com/swmansion/enriched/spans/EditorSpans.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EnrichedSpans.kt @@ -11,7 +11,7 @@ data class StylesMergingConfig( val blockingStyles: Array = emptyArray(), ) -object EditorSpans { +object EnrichedSpans { // inline styles const val BOLD = "bold" const val ITALIC = "italic" @@ -36,30 +36,30 @@ object EditorSpans { const val MENTION = "mention" val inlineSpans: Map = mapOf( - BOLD to BaseSpanConfig(EditorBoldSpan::class.java), - ITALIC to BaseSpanConfig(EditorItalicSpan::class.java), - UNDERLINE to BaseSpanConfig(EditorUnderlineSpan::class.java), - STRIKETHROUGH to BaseSpanConfig(EditorStrikeThroughSpan::class.java), - INLINE_CODE to BaseSpanConfig(EditorInlineCodeSpan::class.java), + BOLD to BaseSpanConfig(EnrichedBoldSpan::class.java), + ITALIC to BaseSpanConfig(EnrichedItalicSpan::class.java), + UNDERLINE to BaseSpanConfig(EnrichedUnderlineSpan::class.java), + STRIKETHROUGH to BaseSpanConfig(EnrichedStrikeThroughSpan::class.java), + INLINE_CODE to BaseSpanConfig(EnrichedInlineCodeSpan::class.java), ) val paragraphSpans: Map = mapOf( - H1 to ParagraphSpanConfig(EditorH1Span::class.java, false), - H2 to ParagraphSpanConfig(EditorH2Span::class.java, false), - H3 to ParagraphSpanConfig(EditorH3Span::class.java, false), - BLOCK_QUOTE to ParagraphSpanConfig(EditorBlockQuoteSpan::class.java, true), - CODE_BLOCK to ParagraphSpanConfig(EditorCodeBlockSpan::class.java, true), + H1 to ParagraphSpanConfig(EnrichedH1Span::class.java, false), + H2 to ParagraphSpanConfig(EnrichedH2Span::class.java, false), + H3 to ParagraphSpanConfig(EnrichedH3Span::class.java, false), + BLOCK_QUOTE to ParagraphSpanConfig(EnrichedBlockQuoteSpan::class.java, true), + CODE_BLOCK to ParagraphSpanConfig(EnrichedCodeBlockSpan::class.java, true), ) val listSpans: Map = mapOf( - UNORDERED_LIST to ListSpanConfig(EditorUnorderedListSpan::class.java, "- "), - ORDERED_LIST to ListSpanConfig(EditorOrderedListSpan::class.java, "1. "), + UNORDERED_LIST to ListSpanConfig(EnrichedUnorderedListSpan::class.java, "- "), + ORDERED_LIST to ListSpanConfig(EnrichedOrderedListSpan::class.java, "1. "), ) val parametrizedStyles: Map = mapOf( - LINK to BaseSpanConfig(EditorLinkSpan::class.java), - IMAGE to BaseSpanConfig(EditorImageSpan::class.java), - MENTION to BaseSpanConfig(EditorMentionSpan::class.java), + LINK to BaseSpanConfig(EnrichedLinkSpan::class.java), + IMAGE to BaseSpanConfig(EnrichedImageSpan::class.java), + MENTION to BaseSpanConfig(EnrichedMentionSpan::class.java), ) val mergingConfig: Map = mapOf( diff --git a/android/src/main/java/com/swmansion/enriched/spans/EnrichedStrikeThroughSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EnrichedStrikeThroughSpan.kt new file mode 100644 index 000000000..46ad5fce5 --- /dev/null +++ b/android/src/main/java/com/swmansion/enriched/spans/EnrichedStrikeThroughSpan.kt @@ -0,0 +1,9 @@ +package com.swmansion.enriched.spans + +import android.text.style.StrikethroughSpan +import com.swmansion.enriched.spans.interfaces.EnrichedInlineSpan +import com.swmansion.enriched.styles.HtmlStyle + +@Suppress("UNUSED_PARAMETER") +class EnrichedStrikeThroughSpan(private val htmlStyle: HtmlStyle) : StrikethroughSpan(), EnrichedInlineSpan { +} diff --git a/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnderlineSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnderlineSpan.kt new file mode 100644 index 000000000..977388c49 --- /dev/null +++ b/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnderlineSpan.kt @@ -0,0 +1,9 @@ +package com.swmansion.enriched.spans + +import android.text.style.UnderlineSpan +import com.swmansion.enriched.spans.interfaces.EnrichedInlineSpan +import com.swmansion.enriched.styles.HtmlStyle + +@Suppress("UNUSED_PARAMETER") +class EnrichedUnderlineSpan(private val htmlStyle: HtmlStyle) : UnderlineSpan(), EnrichedInlineSpan { +} diff --git a/android/src/main/java/com/swmansion/enriched/spans/EditorUnorderedListSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnorderedListSpan.kt similarity index 59% rename from android/src/main/java/com/swmansion/enriched/spans/EditorUnorderedListSpan.kt rename to android/src/main/java/com/swmansion/enriched/spans/EnrichedUnorderedListSpan.kt index 9cc4d6880..52b842238 100644 --- a/android/src/main/java/com/swmansion/enriched/spans/EditorUnorderedListSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnorderedListSpan.kt @@ -5,13 +5,13 @@ import android.graphics.Paint import android.text.Layout import android.text.Spanned import android.text.style.LeadingMarginSpan -import com.swmansion.enriched.spans.interfaces.EditorParagraphSpan -import com.swmansion.enriched.styles.RichTextStyle +import com.swmansion.enriched.spans.interfaces.EnrichedParagraphSpan +import com.swmansion.enriched.styles.HtmlStyle // https://android.googlesource.com/platform/frameworks/base/+/refs/heads/main/core/java/android/text/style/BulletSpan.java -class EditorUnorderedListSpan(private val richTextStyle: RichTextStyle) : LeadingMarginSpan, EditorParagraphSpan { +class EnrichedUnorderedListSpan(private val htmlStyle: HtmlStyle) : LeadingMarginSpan, EnrichedParagraphSpan { override fun getLeadingMargin(p0: Boolean): Int { - return richTextStyle.ulBulletSize + richTextStyle.ulGapWidth + richTextStyle.ulMarginLeft + return htmlStyle.ulBulletSize + htmlStyle.ulGapWidth + htmlStyle.ulMarginLeft } override fun drawLeadingMargin( @@ -32,15 +32,15 @@ class EditorUnorderedListSpan(private val richTextStyle: RichTextStyle) : Leadin if (spannedText.getSpanStart(this) == start) { val style = paint.style - var oldColor = paint.color - paint.color = richTextStyle.ulBulletColor + val oldColor = paint.color + paint.color = htmlStyle.ulBulletColor paint.style = Paint.Style.FILL - val bulletRadius = richTextStyle.ulBulletSize / 2f + val bulletRadius = htmlStyle.ulBulletSize / 2f val yPosition = (top + bottom) / 2f - val xPosition = x + dir * bulletRadius + richTextStyle.ulMarginLeft + val xPosition = x + dir * bulletRadius + htmlStyle.ulMarginLeft - canvas.drawCircle(xPosition.toFloat(), yPosition, bulletRadius, paint) + canvas.drawCircle(xPosition, yPosition, bulletRadius, paint) paint.color = oldColor paint.style = style diff --git a/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorBlockSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorBlockSpan.kt deleted file mode 100644 index 5c0fddd7a..000000000 --- a/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorBlockSpan.kt +++ /dev/null @@ -1,4 +0,0 @@ -package com.swmansion.enriched.spans.interfaces - -interface EditorBlockSpan : EditorSpan, EditorZeroWidthSpaceSpan { -} diff --git a/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorHeadingSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorHeadingSpan.kt deleted file mode 100644 index 293ab4fd3..000000000 --- a/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorHeadingSpan.kt +++ /dev/null @@ -1,4 +0,0 @@ -package com.swmansion.enriched.spans.interfaces - -interface EditorHeadingSpan : EditorParagraphSpan { -} diff --git a/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorParagraphSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorParagraphSpan.kt deleted file mode 100644 index 219dc29b4..000000000 --- a/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorParagraphSpan.kt +++ /dev/null @@ -1,4 +0,0 @@ -package com.swmansion.enriched.spans.interfaces - -interface EditorParagraphSpan : EditorSpan, EditorZeroWidthSpaceSpan { -} diff --git a/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedBlockSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedBlockSpan.kt new file mode 100644 index 000000000..0d18ff5b5 --- /dev/null +++ b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedBlockSpan.kt @@ -0,0 +1,4 @@ +package com.swmansion.enriched.spans.interfaces + +interface EnrichedBlockSpan : EnrichedSpan, EnrichedZeroWidthSpaceSpan { +} diff --git a/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedHeadingSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedHeadingSpan.kt new file mode 100644 index 000000000..5d13f53ce --- /dev/null +++ b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedHeadingSpan.kt @@ -0,0 +1,4 @@ +package com.swmansion.enriched.spans.interfaces + +interface EnrichedHeadingSpan : EnrichedParagraphSpan { +} diff --git a/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorInlineSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedInlineSpan.kt similarity index 52% rename from android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorInlineSpan.kt rename to android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedInlineSpan.kt index e695a2287..559e70ac5 100644 --- a/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorInlineSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedInlineSpan.kt @@ -1,4 +1,4 @@ package com.swmansion.enriched.spans.interfaces -interface EditorInlineSpan : EditorSpan { +interface EnrichedInlineSpan : EnrichedSpan { } diff --git a/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedParagraphSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedParagraphSpan.kt new file mode 100644 index 000000000..72f6d4e44 --- /dev/null +++ b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedParagraphSpan.kt @@ -0,0 +1,4 @@ +package com.swmansion.enriched.spans.interfaces + +interface EnrichedParagraphSpan : EnrichedSpan, EnrichedZeroWidthSpaceSpan { +} diff --git a/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedSpan.kt similarity index 67% rename from android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorSpan.kt rename to android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedSpan.kt index 094fc06f2..5a5de532f 100644 --- a/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedSpan.kt @@ -1,4 +1,4 @@ package com.swmansion.enriched.spans.interfaces -interface EditorSpan { +interface EnrichedSpan { } diff --git a/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorZeroWidthSpaceSpan.kt b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedZeroWidthSpaceSpan.kt similarity index 80% rename from android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorZeroWidthSpaceSpan.kt rename to android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedZeroWidthSpaceSpan.kt index 5d1b29079..470c0a1a4 100644 --- a/android/src/main/java/com/swmansion/enriched/spans/interfaces/EditorZeroWidthSpaceSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedZeroWidthSpaceSpan.kt @@ -1,5 +1,5 @@ package com.swmansion.enriched.spans.interfaces // Spans that are prefixed with zero-width space (\u200B) to ensure that they are visible even when empty. -interface EditorZeroWidthSpaceSpan { +interface EnrichedZeroWidthSpaceSpan { } diff --git a/android/src/main/java/com/swmansion/enriched/styles/RichTextStyle.kt b/android/src/main/java/com/swmansion/enriched/styles/HtmlStyle.kt similarity index 93% rename from android/src/main/java/com/swmansion/enriched/styles/RichTextStyle.kt rename to android/src/main/java/com/swmansion/enriched/styles/HtmlStyle.kt index 9b184c2b1..d93261ed0 100644 --- a/android/src/main/java/com/swmansion/enriched/styles/RichTextStyle.kt +++ b/android/src/main/java/com/swmansion/enriched/styles/HtmlStyle.kt @@ -12,9 +12,9 @@ import kotlin.Int import kotlin.String import kotlin.math.ceil -class RichTextStyle { +class HtmlStyle { private var style: ReadableMap? = null - private var editorView: EnrichedTextInputView? = null + private var view: EnrichedTextInputView? = null // Default values are ignored as they are specified on the JS side. // They are specified only because they are required by the constructor. @@ -58,8 +58,8 @@ class RichTextStyle { var mentionsStyle: MutableMap = mutableMapOf() - constructor(editorView: EnrichedTextInputView?, style: ReadableMap?) { - this.editorView = editorView + constructor(view: EnrichedTextInputView?, style: ReadableMap?) { + this.view = view this.style = style invalidateStyles() @@ -88,7 +88,7 @@ class RichTextStyle { val olStyle = style.getMap("ol") val userDefinedMarginLeft = parseFloat(olStyle, "marginLeft").toInt() - val calculatedMarginLeft = calculateOlMarginLeft(editorView, userDefinedMarginLeft) + val calculatedMarginLeft = calculateOlMarginLeft(view, userDefinedMarginLeft) olMarginLeft = calculatedMarginLeft olGapWidth = parseFloat(olStyle, "gapWidth").toInt() olMarkerColor = parseOptionalColor(olStyle, "markerColor") @@ -145,7 +145,7 @@ class RichTextStyle { val safeMap = ensureValueIsSet(map, key) val color = safeMap.getDouble(key) - val parsedColor = ColorPropConverter.getColor(color, editorView?.context as ReactContext) + val parsedColor = ColorPropConverter.getColor(color, view?.context as ReactContext) if (parsedColor == null) { throw Error("Specified color value is not supported: $color") } @@ -169,8 +169,8 @@ class RichTextStyle { throw Error("Specified textDecorationLine value is not supported: $underline. Supported values are 'underline' and 'none'.") } - private fun calculateOlMarginLeft(editorView: EnrichedTextInputView?, userMargin: Int): Int { - val fontSize = editorView?.fontSize?.toInt() ?: 0 + private fun calculateOlMarginLeft(view: EnrichedTextInputView?, userMargin: Int): Int { + val fontSize = view?.fontSize?.toInt() ?: 0 val leadMargin = fontSize / 2 return leadMargin + userMargin diff --git a/android/src/main/java/com/swmansion/enriched/styles/InlineStyles.kt b/android/src/main/java/com/swmansion/enriched/styles/InlineStyles.kt index 2866089c8..41581c0f8 100644 --- a/android/src/main/java/com/swmansion/enriched/styles/InlineStyles.kt +++ b/android/src/main/java/com/swmansion/enriched/styles/InlineStyles.kt @@ -3,10 +3,10 @@ package com.swmansion.enriched.styles import android.text.Editable import android.text.Spannable import com.swmansion.enriched.EnrichedTextInputView -import com.swmansion.enriched.spans.EditorSpans +import com.swmansion.enriched.spans.EnrichedSpans import com.swmansion.enriched.utils.getSafeSpanBoundaries -class InlineStyles(private val editorView: EnrichedTextInputView) { +class InlineStyles(private val view: EnrichedTextInputView) { private fun setSpan(spannable: Spannable, type: Class, start: Int, end: Int) { val previousSpanStart = (start - 1).coerceAtLeast(0) val previousSpanEnd = previousSpanStart + 1 @@ -32,7 +32,7 @@ class InlineStyles(private val editorView: EnrichedTextInputView) { spannable.removeSpan(span) } - val span = type.getDeclaredConstructor(RichTextStyle::class.java).newInstance(editorView.richTextStyle) + val span = type.getDeclaredConstructor(HtmlStyle::class.java).newInstance(view.htmlStyle) val (safeStart, safeEnd) = spannable.getSafeSpanBoundaries(minimum, maximum) spannable.setSpan(span, safeStart, safeEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) } @@ -89,8 +89,8 @@ class InlineStyles(private val editorView: EnrichedTextInputView) { } fun afterTextChanged(s: Editable, endCursorPosition: Int) { - for ((style, config) in EditorSpans.inlineSpans) { - val start = editorView.spanState?.getStart(style) ?: continue + for ((style, config) in EnrichedSpans.inlineSpans) { + val start = view.spanState?.getStart(style) ?: continue var end = endCursorPosition val spans = s.getSpans(start, end, config.clazz) @@ -104,32 +104,32 @@ class InlineStyles(private val editorView: EnrichedTextInputView) { } fun toggleStyle(name: String) { - if (editorView.selection == null) return - val (start, end) = editorView.selection.getInlineSelection() - val config = EditorSpans.inlineSpans[name] ?: return + if (view.selection == null) return + val (start, end) = view.selection.getInlineSelection() + val config = EnrichedSpans.inlineSpans[name] ?: return val type = config.clazz // We either start or end current span if (start == end) { - val styleStart = editorView.spanState?.getStart(name) + val styleStart = view.spanState?.getStart(name) if (styleStart != null) { - editorView.spanState.setStart(name, null) + view.spanState.setStart(name, null) } else { - editorView.spanState?.setStart(name, start) + view.spanState?.setStart(name, start) } return } - val spannable = editorView.text as Spannable + val spannable = view.text as Spannable setAndMergeSpans(spannable, type, start, end) - editorView.selection.validateStyles() + view.selection.validateStyles() } fun removeStyle(name: String, start: Int, end: Int): Boolean { - val config = EditorSpans.inlineSpans[name] ?: return false - val spannable = editorView.text as Spannable + val config = EnrichedSpans.inlineSpans[name] ?: return false + val spannable = view.text as Spannable val spans = spannable.getSpans(start, end, config.clazz) if (spans.isEmpty()) return false @@ -141,6 +141,6 @@ class InlineStyles(private val editorView: EnrichedTextInputView) { } fun getStyleRange(): Pair { - return editorView.selection?.getInlineSelection() ?: Pair(0, 0) + return view.selection?.getInlineSelection() ?: Pair(0, 0) } } diff --git a/android/src/main/java/com/swmansion/enriched/styles/ListStyles.kt b/android/src/main/java/com/swmansion/enriched/styles/ListStyles.kt index a183472f7..82fdd9c95 100644 --- a/android/src/main/java/com/swmansion/enriched/styles/ListStyles.kt +++ b/android/src/main/java/com/swmansion/enriched/styles/ListStyles.kt @@ -5,13 +5,13 @@ import android.text.Spannable import android.text.SpannableStringBuilder import android.text.Spanned import com.swmansion.enriched.EnrichedTextInputView -import com.swmansion.enriched.spans.EditorOrderedListSpan -import com.swmansion.enriched.spans.EditorSpans -import com.swmansion.enriched.spans.EditorUnorderedListSpan +import com.swmansion.enriched.spans.EnrichedOrderedListSpan +import com.swmansion.enriched.spans.EnrichedSpans +import com.swmansion.enriched.spans.EnrichedUnorderedListSpan import com.swmansion.enriched.utils.getParagraphBounds import com.swmansion.enriched.utils.getSafeSpanBoundaries -class ListStyles(private val editorView: EnrichedTextInputView) { +class ListStyles(private val view: EnrichedTextInputView) { private fun getPreviousParagraphSpan(spannable: Spannable, s: Int, type: Class): T? { if (s <= 0) return null @@ -32,7 +32,7 @@ class ListStyles(private val editorView: EnrichedTextInputView) { } private fun getOrderedListIndex(spannable: Spannable, s: Int): Int { - val span = getPreviousParagraphSpan(spannable, s, EditorOrderedListSpan::class.java) + val span = getPreviousParagraphSpan(spannable, s, EnrichedOrderedListSpan::class.java) val index = span?.getIndex() ?: 0 return index + 1 } @@ -40,15 +40,15 @@ class ListStyles(private val editorView: EnrichedTextInputView) { private fun setSpan(spannable: Spannable, name: String, start: Int, end: Int) { val (safeStart, safeEnd) = spannable.getSafeSpanBoundaries(start, end) - if (name == EditorSpans.UNORDERED_LIST) { - val span = EditorUnorderedListSpan(editorView.richTextStyle) + if (name == EnrichedSpans.UNORDERED_LIST) { + val span = EnrichedUnorderedListSpan(view.htmlStyle) spannable.setSpan(span, safeStart, safeEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) return } - if (name == EditorSpans.ORDERED_LIST) { + if (name == EnrichedSpans.ORDERED_LIST) { val index = getOrderedListIndex(spannable, safeStart) - val span = EditorOrderedListSpan(index, editorView.richTextStyle) + val span = EnrichedOrderedListSpan(index, view.htmlStyle) spannable.setSpan(span, safeStart, safeEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) } } @@ -68,7 +68,7 @@ class ListStyles(private val editorView: EnrichedTextInputView) { } fun updateOrderedListIndexes(text: Spannable, position: Int) { - val spans = text.getSpans(position + 1, text.length, EditorOrderedListSpan::class.java) + val spans = text.getSpans(position + 1, text.length, EnrichedOrderedListSpan::class.java) for (span in spans) { val spanStart = text.getSpanStart(span) val index = getOrderedListIndex(text, spanStart) @@ -77,23 +77,23 @@ class ListStyles(private val editorView: EnrichedTextInputView) { } fun toggleStyle(name: String) { - if (editorView.selection == null) return - val config = EditorSpans.listSpans[name] ?: return - val spannable = editorView.text as SpannableStringBuilder - var (start, end) = editorView.selection.getParagraphSelection() - val styleStart = editorView.spanState?.getStart(name) + if (view.selection == null) return + val config = EnrichedSpans.listSpans[name] ?: return + val spannable = view.text as SpannableStringBuilder + val (start, end) = view.selection.getParagraphSelection() + val styleStart = view.spanState?.getStart(name) if (styleStart != null) { - editorView.spanState.setStart(name, null) + view.spanState.setStart(name, null) removeSpansForRange(spannable, start, end, config.clazz) - editorView.selection.validateStyles() + view.selection.validateStyles() return } if (start == end) { spannable.insert(start, "\u200B") - editorView.spanState?.setStart(name, start + 1) + view.spanState?.setStart(name, start + 1) removeSpansForRange(spannable, start, end, config.clazz) setSpan(spannable, name, start, end + 1) @@ -112,11 +112,11 @@ class ListStyles(private val editorView: EnrichedTextInputView) { currentStart = currentEnd + 1 } - editorView.spanState?.setStart(name, currentStart) + view.spanState?.setStart(name, currentStart) } private fun handleAfterTextChanged(s: Editable, name: String, endCursorPosition: Int, previousTextLength: Int) { - val config = EditorSpans.listSpans[name] ?: return + val config = EnrichedSpans.listSpans[name] ?: return val cursorPosition = endCursorPosition.coerceAtMost(s.length) val (start, end) = s.getParagraphBounds(cursorPosition) @@ -135,7 +135,7 @@ class ListStyles(private val editorView: EnrichedTextInputView) { s.replace(start, cursorPosition, "\u200B") setSpan(s, name, start, start + 1) // Inform that new span has been added - editorView.selection?.validateStyles() + view.selection?.validateStyles() return } @@ -143,7 +143,7 @@ class ListStyles(private val editorView: EnrichedTextInputView) { s.insert(cursorPosition, "\u200B") setSpan(s, name, start, end + 1) // Inform that new span has been added - editorView.selection?.validateStyles() + view.selection?.validateStyles() return } @@ -157,17 +157,17 @@ class ListStyles(private val editorView: EnrichedTextInputView) { } fun afterTextChanged(s: Editable, endCursorPosition: Int, previousTextLength: Int) { - handleAfterTextChanged(s, EditorSpans.ORDERED_LIST, endCursorPosition, previousTextLength) - handleAfterTextChanged(s, EditorSpans.UNORDERED_LIST, endCursorPosition, previousTextLength) + handleAfterTextChanged(s, EnrichedSpans.ORDERED_LIST, endCursorPosition, previousTextLength) + handleAfterTextChanged(s, EnrichedSpans.UNORDERED_LIST, endCursorPosition, previousTextLength) } fun getStyleRange(): Pair { - return editorView.selection?.getParagraphSelection() ?: Pair(0, 0) + return view.selection?.getParagraphSelection() ?: Pair(0, 0) } fun removeStyle(name: String, start: Int, end: Int): Boolean { - val config = EditorSpans.listSpans[name] ?: return false - val spannable = editorView.text as Spannable + val config = EnrichedSpans.listSpans[name] ?: return false + val spannable = view.text as Spannable return removeSpansForRange(spannable, start, end, config.clazz) } } diff --git a/android/src/main/java/com/swmansion/enriched/styles/ParagraphStyles.kt b/android/src/main/java/com/swmansion/enriched/styles/ParagraphStyles.kt index 7e31af7f8..2d3d0b801 100644 --- a/android/src/main/java/com/swmansion/enriched/styles/ParagraphStyles.kt +++ b/android/src/main/java/com/swmansion/enriched/styles/ParagraphStyles.kt @@ -4,13 +4,13 @@ import android.text.Editable import android.text.Spannable import android.text.SpannableStringBuilder import com.swmansion.enriched.EnrichedTextInputView -import com.swmansion.enriched.spans.EditorSpans +import com.swmansion.enriched.spans.EnrichedSpans import com.swmansion.enriched.utils.getParagraphBounds import com.swmansion.enriched.utils.getSafeSpanBoundaries -class ParagraphStyles(private val editorView: EnrichedTextInputView) { +class ParagraphStyles(private val view: EnrichedTextInputView) { private fun setSpan(spannable: Spannable, type: Class, start: Int, end: Int) { - val span = type.getDeclaredConstructor(RichTextStyle::class.java).newInstance(editorView.richTextStyle) + val span = type.getDeclaredConstructor(HtmlStyle::class.java).newInstance(view.htmlStyle) val (safeStart, safeEnd) = spannable.getSafeSpanBoundaries(start, end) spannable.setSpan(span, safeStart, safeEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) } @@ -86,7 +86,7 @@ class ParagraphStyles(private val editorView: EnrichedTextInputView) { } private fun isSpanEnabledInNextLine(spannable: Spannable, index: Int, type: Class): Boolean { - val selection = editorView.selection ?: return false + val selection = view.selection ?: return false if (index + 1 >= spannable.length) return false val (start, end) = selection.getParagraphSelection() @@ -99,8 +99,8 @@ class ParagraphStyles(private val editorView: EnrichedTextInputView) { val isBackspace = s.length < previousTextLength val isNewLine = endCursorPosition == 0 || endCursorPosition > 0 && s[endCursorPosition - 1] == '\n' - for ((style, config) in EditorSpans.paragraphSpans) { - val spanState = editorView.spanState ?: continue + for ((style, config) in EnrichedSpans.paragraphSpans) { + val spanState = view.spanState ?: continue val styleStart = spanState.getStart(style) ?: continue if (isNewLine) { @@ -111,7 +111,7 @@ class ParagraphStyles(private val editorView: EnrichedTextInputView) { if (isBackspace) { endCursorPosition -= 1 - editorView.spanState.setStart(style, null) + view.spanState.setStart(style, null) } else { s.insert(endCursorPosition, "\u200B") endCursorPosition += 1 @@ -136,25 +136,25 @@ class ParagraphStyles(private val editorView: EnrichedTextInputView) { } fun toggleStyle(name: String) { - if (editorView.selection == null) return - val spannable = editorView.text as SpannableStringBuilder - var (start, end) = editorView.selection.getParagraphSelection() - val config = EditorSpans.paragraphSpans[name] ?: return + if (view.selection == null) return + val spannable = view.text as SpannableStringBuilder + val (start, end) = view.selection.getParagraphSelection() + val config = EnrichedSpans.paragraphSpans[name] ?: return val type = config.clazz - val styleStart = editorView.spanState?.getStart(name) + val styleStart = view.spanState?.getStart(name) if (styleStart != null) { - editorView.spanState.setStart(name, null) + view.spanState.setStart(name, null) removeSpansForRange(spannable, start, end, type) - editorView.selection.validateStyles() + view.selection.validateStyles() return } if (start == end) { spannable.insert(start, "\u200B") - editorView.spanState?.setStart(name, start + 1) + view.spanState?.setStart(name, start + 1) setAndMergeSpans(spannable, type, start, end + 1) return @@ -170,17 +170,17 @@ class ParagraphStyles(private val editorView: EnrichedTextInputView) { currentStart = currentEnd + 1 } - editorView.spanState?.setStart(name, start) + view.spanState?.setStart(name, start) setAndMergeSpans(spannable, type, start, currentEnd) } fun getStyleRange(): Pair { - return editorView.selection?.getParagraphSelection() ?: Pair(0, 0) + return view.selection?.getParagraphSelection() ?: Pair(0, 0) } fun removeStyle(name: String, start: Int, end: Int): Boolean { - val config = EditorSpans.paragraphSpans[name] ?: return false - val spannable = editorView.text as Spannable + val config = EnrichedSpans.paragraphSpans[name] ?: return false + val spannable = view.text as Spannable return removeSpansForRange(spannable, start, end, config.clazz) } } diff --git a/android/src/main/java/com/swmansion/enriched/styles/ParametrizedStyles.kt b/android/src/main/java/com/swmansion/enriched/styles/ParametrizedStyles.kt index 26b5ab6ea..acddfac7b 100644 --- a/android/src/main/java/com/swmansion/enriched/styles/ParametrizedStyles.kt +++ b/android/src/main/java/com/swmansion/enriched/styles/ParametrizedStyles.kt @@ -6,14 +6,14 @@ import android.text.Spannable import android.text.SpannableStringBuilder import android.text.Spanned import com.swmansion.enriched.EnrichedTextInputView -import com.swmansion.enriched.spans.EditorImageSpan -import com.swmansion.enriched.spans.EditorLinkSpan -import com.swmansion.enriched.spans.EditorMentionSpan -import com.swmansion.enriched.spans.EditorSpans +import com.swmansion.enriched.spans.EnrichedImageSpan +import com.swmansion.enriched.spans.EnrichedLinkSpan +import com.swmansion.enriched.spans.EnrichedMentionSpan +import com.swmansion.enriched.spans.EnrichedSpans import com.swmansion.enriched.utils.getSafeSpanBoundaries import java.io.File -class ParametrizedStyles(private val editorView: EnrichedTextInputView) { +class ParametrizedStyles(private val view: EnrichedTextInputView) { private var mentionStart: Int? = null private var isSettingLinkSpan = false @@ -36,8 +36,8 @@ class ParametrizedStyles(private val editorView: EnrichedTextInputView) { fun setLinkSpan(start: Int, end: Int, text: String, url: String) { isSettingLinkSpan = true - val spannable = editorView.text as SpannableStringBuilder - val spans = spannable.getSpans(start, end, EditorLinkSpan::class.java) + val spannable = view.text as SpannableStringBuilder + val spans = spannable.getSpans(start, end, EnrichedLinkSpan::class.java) for (span in spans) { spannable.removeSpan(span) } @@ -49,11 +49,11 @@ class ParametrizedStyles(private val editorView: EnrichedTextInputView) { } val spanEnd = start + text.length - val span = EditorLinkSpan(url, editorView.richTextStyle) + val span = EnrichedLinkSpan(url, view.htmlStyle) val (safeStart, safeEnd) = spannable.getSafeSpanBoundaries(start, spanEnd) spannable.setSpan(span, safeStart, safeEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) - editorView.selection?.validateStyles() + view.selection?.validateStyles() isSettingLinkSpan = false } @@ -65,12 +65,12 @@ class ParametrizedStyles(private val editorView: EnrichedTextInputView) { } fun detectAllLinks() { - val spannable = editorView.text as Spannable + val spannable = view.text as Spannable // TODO: Consider using more reliable regex, this one matches almost anything val urlPattern = android.util.Patterns.WEB_URL.matcher(spannable) - val spans = spannable.getSpans(0, spannable.length, EditorLinkSpan::class.java) + val spans = spannable.getSpans(0, spannable.length, EnrichedLinkSpan::class.java) for (span in spans) { spannable.removeSpan(span) } @@ -79,7 +79,7 @@ class ParametrizedStyles(private val editorView: EnrichedTextInputView) { val word = urlPattern.group() val start = urlPattern.start() val end = urlPattern.end() - val span = EditorLinkSpan(word, editorView.richTextStyle) + val span = EnrichedLinkSpan(word, view.htmlStyle) val (safeStart, safeEnd) = spannable.getSafeSpanBoundaries(start, end) spannable.setSpan(span, safeStart, safeEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) } @@ -107,34 +107,34 @@ class ParametrizedStyles(private val editorView: EnrichedTextInputView) { private fun afterTextChangedLinks(result: Triple) { // Do not detect link if it's applied manually if (isSettingLinkSpan) return - val spannable = editorView.text as Spannable + val spannable = view.text as Spannable val (word, start, end) = result // TODO: Consider using more reliable regex, this one matches almost anything val urlPattern = android.util.Patterns.WEB_URL.matcher(word) - val spans = spannable.getSpans(start, end, EditorLinkSpan::class.java) + val spans = spannable.getSpans(start, end, EnrichedLinkSpan::class.java) for (span in spans) { spannable.removeSpan(span) } if (urlPattern.matches()) { - val span = EditorLinkSpan(word, editorView.richTextStyle) + val span = EnrichedLinkSpan(word, view.htmlStyle) val (safeStart, safeEnd) = spannable.getSafeSpanBoundaries(start, end) spannable.setSpan(span, safeStart, safeEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) } } private fun afterTextChangedMentions(result: Triple) { - val mentionHandler = editorView.mentionHandler ?: return - val spannable = editorView.text as Spannable + val mentionHandler = view.mentionHandler ?: return + val spannable = view.text as Spannable val (word, start, end) = result val indicatorsPattern = mentionIndicators.joinToString("|") { Regex.escape(it) } val mentionIndicatorRegex = Regex("^($indicatorsPattern)") val mentionRegex= Regex("^($indicatorsPattern)\\w*") - val spans = spannable.getSpans(start, end, EditorMentionSpan::class.java) + val spans = spannable.getSpans(start, end, EnrichedMentionSpan::class.java) for (span in spans) { spannable.removeSpan(span) } @@ -155,11 +155,11 @@ class ParametrizedStyles(private val editorView: EnrichedTextInputView) { } fun setImageSpan(src: String) { - if (editorView.selection == null) return + if (view.selection == null) return - val spannable = editorView.text as SpannableStringBuilder - var (start, end) = editorView.selection.getInlineSelection() - val spans = spannable.getSpans(start, end, EditorImageSpan::class.java) + val spannable = view.text as SpannableStringBuilder + var (start, end) = view.selection.getInlineSelection() + val spans = spannable.getSpans(start, end, EnrichedImageSpan::class.java) for (s in spans) { spannable.removeSpan(s) @@ -171,16 +171,16 @@ class ParametrizedStyles(private val editorView: EnrichedTextInputView) { } val uri = Uri.fromFile(File(src)) - val span = EditorImageSpan(editorView.context, uri, editorView.richTextStyle) + val span = EnrichedImageSpan(view.context, uri, view.htmlStyle) val (safeStart, safeEnd) = spannable.getSafeSpanBoundaries(start, end) spannable.setSpan(span, safeStart, safeEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) } fun startMention(indicator: String) { - val selection = editorView.selection ?: return + val selection = view.selection ?: return - val spannable = editorView.text as SpannableStringBuilder - var (start, end) = selection.getInlineSelection() + val spannable = view.text as SpannableStringBuilder + val (start, end) = selection.getInlineSelection() if (start == end) { spannable.insert(start, indicator) @@ -190,34 +190,34 @@ class ParametrizedStyles(private val editorView: EnrichedTextInputView) { } fun setMentionSpan(indicator: String, text: String, attributes: Map) { - val selection = editorView.selection ?: return + val selection = view.selection ?: return - val spannable = editorView.text as SpannableStringBuilder - var (selectionStart, selectionEnd) = selection.getInlineSelection() - val spans = spannable.getSpans(selectionStart, selectionEnd, EditorMentionSpan::class.java) + val spannable = view.text as SpannableStringBuilder + val (selectionStart, selectionEnd) = selection.getInlineSelection() + val spans = spannable.getSpans(selectionStart, selectionEnd, EnrichedMentionSpan::class.java) for (span in spans) { spannable.removeSpan(span) } - var start = mentionStart ?: return + val start = mentionStart ?: return spannable.replace(start, selectionEnd, text) - val span = EditorMentionSpan(text, indicator, attributes, editorView.richTextStyle) + val span = EnrichedMentionSpan(text, indicator, attributes, view.htmlStyle) val spanEnd = start + text.length val (safeStart, safeEnd) = spannable.getSafeSpanBoundaries(start, spanEnd) spannable.setSpan(span, safeStart, safeEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) - editorView.selection.validateStyles() + view.selection.validateStyles() } fun getStyleRange(): Pair { - return editorView.selection?.getInlineSelection() ?: Pair(0, 0) + return view.selection?.getInlineSelection() ?: Pair(0, 0) } fun removeStyle(name: String, start: Int, end: Int): Boolean { - val config = EditorSpans.parametrizedStyles[name] ?: return false - val spannable = editorView.text as Spannable + val config = EnrichedSpans.parametrizedStyles[name] ?: return false + val spannable = view.text as Spannable return removeSpansForRange(spannable, start, end, config.clazz) } } diff --git a/android/src/main/java/com/swmansion/enriched/utils/EditorSelection.kt b/android/src/main/java/com/swmansion/enriched/utils/EditorSelection.kt index 650c7e502..0f130ecba 100644 --- a/android/src/main/java/com/swmansion/enriched/utils/EditorSelection.kt +++ b/android/src/main/java/com/swmansion/enriched/utils/EditorSelection.kt @@ -8,12 +8,12 @@ import com.swmansion.enriched.EnrichedTextInputView import com.swmansion.enriched.events.OnChangeSelectionEvent import com.swmansion.enriched.events.OnLinkDetectedEvent import com.swmansion.enriched.events.OnMentionDetectedEvent -import com.swmansion.enriched.spans.EditorLinkSpan -import com.swmansion.enriched.spans.EditorMentionSpan -import com.swmansion.enriched.spans.EditorSpans +import com.swmansion.enriched.spans.EnrichedLinkSpan +import com.swmansion.enriched.spans.EnrichedMentionSpan +import com.swmansion.enriched.spans.EnrichedSpans import org.json.JSONObject -class EditorSelection(private val editorView: EnrichedTextInputView) { +class EnrichedSelection(private val view: EnrichedTextInputView) { var start: Int = 0 var end: Int = 0 @@ -35,12 +35,12 @@ class EditorSelection(private val editorView: EnrichedTextInputView) { shouldValidateStyles = true } - val textLength = editorView.text?.length ?: 0 + val textLength = view.text?.length ?: 0 val finalStart = newStart.coerceAtMost(newEnd).coerceAtLeast(0).coerceAtMost(textLength) val finalEnd = newEnd.coerceAtLeast(newStart).coerceAtLeast(0).coerceAtMost(textLength) - if (isZeroWidthSelection(finalStart, finalEnd) && !editorView.isSettingValue) { - editorView.setSelection(finalStart + 1) + if (isZeroWidthSelection(finalStart, finalEnd) && !view.isSettingValue) { + view.setSelection(finalStart + 1) shouldValidateStyles = false } @@ -49,11 +49,11 @@ class EditorSelection(private val editorView: EnrichedTextInputView) { start = finalStart end = finalEnd validateStyles() - emitSelectionChangeEvent(editorView.text, finalStart, finalEnd) + emitSelectionChangeEvent(view.text, finalStart, finalEnd) } private fun isZeroWidthSelection(start: Int, end: Int): Boolean { - val text = editorView.text ?: return false + val text = view.text ?: return false if (start != end) { return text.substring(start, end) == "\u200B" @@ -70,28 +70,28 @@ class EditorSelection(private val editorView: EnrichedTextInputView) { } fun validateStyles() { - val state = editorView.spanState ?: return + val state = view.spanState ?: return // We don't validate inline styles when removing many characters at once // We don't want to remove styles on auto-correction // If user removes many characters at once, we want to keep the styles config - if (!editorView.isRemovingMany) { - for ((style, config) in EditorSpans.inlineSpans) { + if (!view.isRemovingMany) { + for ((style, config) in EnrichedSpans.inlineSpans) { state.setStart(style, getInlineStyleStart(config.clazz)) } } else { - editorView.isRemovingMany = false + view.isRemovingMany = false } - for ((style, config) in EditorSpans.paragraphSpans) { + for ((style, config) in EnrichedSpans.paragraphSpans) { state.setStart(style, getParagraphStyleStart(config.clazz)) } - for ((style, config) in EditorSpans.listSpans) { + for ((style, config) in EnrichedSpans.listSpans) { state.setStart(style, getListStyleStart(config.clazz)) } - for ((style, config) in EditorSpans.parametrizedStyles) { + for ((style, config) in EnrichedSpans.parametrizedStyles) { state.setStart(style, getParametrizedStyleStart(config.clazz)) } } @@ -105,7 +105,7 @@ class EditorSelection(private val editorView: EnrichedTextInputView) { private fun getInlineStyleStart(type: Class): Int? { val (start, end) = getInlineSelection() - val spannable = editorView.text as Spannable + val spannable = view.text as Spannable val spans = spannable.getSpans(start, end, type) var styleStart: Int? = null @@ -125,13 +125,13 @@ class EditorSelection(private val editorView: EnrichedTextInputView) { fun getParagraphSelection(): Pair { val (currentStart, currentEnd) = getInlineSelection() - val spannable = editorView.text as Spannable + val spannable = view.text as Spannable return spannable.getParagraphBounds(currentStart, currentEnd) } private fun getParagraphStyleStart(type: Class): Int? { val (start, end) = getParagraphSelection() - val spannable = editorView.text as Spannable + val spannable = view.text as Spannable val spans = spannable.getSpans(start, end, type) var styleStart: Int? = null @@ -150,7 +150,7 @@ class EditorSelection(private val editorView: EnrichedTextInputView) { private fun getListStyleStart(type: Class): Int? { val (start, end) = getParagraphSelection() - val spannable = editorView.text as Spannable + val spannable = view.text as Spannable var styleStart: Int? = null var paragraphStart = start @@ -179,10 +179,10 @@ class EditorSelection(private val editorView: EnrichedTextInputView) { private fun getParametrizedStyleStart(type: Class): Int? { val (start, end) = getInlineSelection() - val spannable = editorView.text as Spannable + val spannable = view.text as Spannable val spans = spannable.getSpans(start, end, type) - val isLinkType = type == EditorLinkSpan::class.java - val isMentionType = type == EditorMentionSpan::class.java + val isLinkType = type == EnrichedLinkSpan::class.java + val isMentionType = type == EnrichedMentionSpan::class.java if (isLinkType && spans.isEmpty()) { emitLinkDetectedEvent(spannable, null, start, end) @@ -199,9 +199,9 @@ class EditorSelection(private val editorView: EnrichedTextInputView) { val spanEnd = spannable.getSpanEnd(span) if (start >= spanStart && end <= spanEnd) { - if (isLinkType && span is EditorLinkSpan) { + if (isLinkType && span is EnrichedLinkSpan) { emitLinkDetectedEvent(spannable, span, spanStart, spanEnd) - } else if (isMentionType && span is EditorMentionSpan) { + } else if (isMentionType && span is EnrichedMentionSpan) { emitMentionDetectedEvent(spannable, span, spanStart, spanEnd) } @@ -215,15 +215,15 @@ class EditorSelection(private val editorView: EnrichedTextInputView) { private fun emitSelectionChangeEvent(editable: Editable?, start: Int, end: Int) { if (editable == null) return - val context = editorView.context as ReactContext + val context = view.context as ReactContext val surfaceId = UIManagerHelper.getSurfaceId(context) - val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, editorView.id) + val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, view.id) val text = editable.substring(start, end) - dispatcher?.dispatchEvent(OnChangeSelectionEvent(surfaceId, editorView.id, text, start ,end)) + dispatcher?.dispatchEvent(OnChangeSelectionEvent(surfaceId, view.id, text, start ,end)) } - private fun emitLinkDetectedEvent(spannable: Spannable, span: EditorLinkSpan?, start: Int, end: Int) { + private fun emitLinkDetectedEvent(spannable: Spannable, span: EnrichedLinkSpan?, start: Int, end: Int) { val text = spannable.substring(start, end) val url = span?.getUrl() ?: "" @@ -233,13 +233,13 @@ class EditorSelection(private val editorView: EnrichedTextInputView) { previousLinkDetectedEvent.put("text", text) previousLinkDetectedEvent.put("url", url) - val context = editorView.context as ReactContext + val context = view.context as ReactContext val surfaceId = UIManagerHelper.getSurfaceId(context) - val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, editorView.id) - dispatcher?.dispatchEvent(OnLinkDetectedEvent(surfaceId, editorView.id, text, url, start, end)) + val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, view.id) + dispatcher?.dispatchEvent(OnLinkDetectedEvent(surfaceId, view.id, text, url, start, end)) } - private fun emitMentionDetectedEvent(spannable: Spannable, span: EditorMentionSpan?, start: Int, end: Int) { + private fun emitMentionDetectedEvent(spannable: Spannable, span: EnrichedMentionSpan?, start: Int, end: Int) { val text = spannable.substring(start, end) val attributes = span?.getAttributes() ?: emptyMap() val indicator = span?.getIndicator() ?: "" @@ -255,9 +255,9 @@ class EditorSelection(private val editorView: EnrichedTextInputView) { previousMentionDetectedEvent.put("payload", payload) previousMentionDetectedEvent.put("indicator", indicator) - val context = editorView.context as ReactContext + val context = view.context as ReactContext val surfaceId = UIManagerHelper.getSurfaceId(context) - val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, editorView.id) - dispatcher?.dispatchEvent(OnMentionDetectedEvent(surfaceId, editorView.id, text, indicator, payload)) + val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, view.id) + dispatcher?.dispatchEvent(OnMentionDetectedEvent(surfaceId, view.id, text, indicator, payload)) } } diff --git a/android/src/main/java/com/swmansion/enriched/utils/EditorSpanSpate.kt b/android/src/main/java/com/swmansion/enriched/utils/EditorSpanSpate.kt index b8030f924..13a567271 100644 --- a/android/src/main/java/com/swmansion/enriched/utils/EditorSpanSpate.kt +++ b/android/src/main/java/com/swmansion/enriched/utils/EditorSpanSpate.kt @@ -6,9 +6,9 @@ import com.facebook.react.bridge.WritableMap import com.facebook.react.uimanager.UIManagerHelper import com.swmansion.enriched.EnrichedTextInputView import com.swmansion.enriched.events.OnChangeStateEvent -import com.swmansion.enriched.spans.EditorSpans +import com.swmansion.enriched.spans.EnrichedSpans -class EditorSpanState(private val editorView: EnrichedTextInputView) { +class EnrichedSpanState(private val view: EnrichedTextInputView) { private var previousPayload: WritableMap? = null var boldStart: Int? = null @@ -119,21 +119,21 @@ class EditorSpanState(private val editorView: EnrichedTextInputView) { fun getStart(name: String): Int? { val start = when (name) { - EditorSpans.BOLD -> boldStart - EditorSpans.ITALIC -> italicStart - EditorSpans.UNDERLINE -> underlineStart - EditorSpans.STRIKETHROUGH -> strikethroughStart - EditorSpans.INLINE_CODE -> inlineCodeStart - EditorSpans.H1 -> h1Start - EditorSpans.H2 -> h2Start - EditorSpans.H3 -> h3Start - EditorSpans.CODE_BLOCK -> codeBlockStart - EditorSpans.BLOCK_QUOTE -> blockQuoteStart - EditorSpans.ORDERED_LIST -> orderedListStart - EditorSpans.UNORDERED_LIST -> unorderedListStart - EditorSpans.LINK -> linkStart - EditorSpans.IMAGE -> imageStart - EditorSpans.MENTION -> mentionStart + EnrichedSpans.BOLD -> boldStart + EnrichedSpans.ITALIC -> italicStart + EnrichedSpans.UNDERLINE -> underlineStart + EnrichedSpans.STRIKETHROUGH -> strikethroughStart + EnrichedSpans.INLINE_CODE -> inlineCodeStart + EnrichedSpans.H1 -> h1Start + EnrichedSpans.H2 -> h2Start + EnrichedSpans.H3 -> h3Start + EnrichedSpans.CODE_BLOCK -> codeBlockStart + EnrichedSpans.BLOCK_QUOTE -> blockQuoteStart + EnrichedSpans.ORDERED_LIST -> orderedListStart + EnrichedSpans.UNORDERED_LIST -> unorderedListStart + EnrichedSpans.LINK -> linkStart + EnrichedSpans.IMAGE -> imageStart + EnrichedSpans.MENTION -> mentionStart else -> null } @@ -142,21 +142,21 @@ class EditorSpanState(private val editorView: EnrichedTextInputView) { fun setStart(name: String, start: Int?) { when (name) { - EditorSpans.BOLD -> setBoldStart(start) - EditorSpans.ITALIC -> setItalicStart(start) - EditorSpans.UNDERLINE -> setUnderlineStart(start) - EditorSpans.STRIKETHROUGH -> setStrikethroughStart(start) - EditorSpans.INLINE_CODE -> setInlineCodeStart(start) - EditorSpans.H1 -> setH1Start(start) - EditorSpans.H2 -> setH2Start(start) - EditorSpans.H3 -> setH3Start(start) - EditorSpans.CODE_BLOCK -> setCodeBlockStart(start) - EditorSpans.BLOCK_QUOTE -> setBlockQuoteStart(start) - EditorSpans.ORDERED_LIST -> setOrderedListStart(start) - EditorSpans.UNORDERED_LIST -> setUnorderedListStart(start) - EditorSpans.LINK -> setLinkStart(start) - EditorSpans.IMAGE -> setImageStart(start) - EditorSpans.MENTION -> setMentionStart(start) + EnrichedSpans.BOLD -> setBoldStart(start) + EnrichedSpans.ITALIC -> setItalicStart(start) + EnrichedSpans.UNDERLINE -> setUnderlineStart(start) + EnrichedSpans.STRIKETHROUGH -> setStrikethroughStart(start) + EnrichedSpans.INLINE_CODE -> setInlineCodeStart(start) + EnrichedSpans.H1 -> setH1Start(start) + EnrichedSpans.H2 -> setH2Start(start) + EnrichedSpans.H3 -> setH3Start(start) + EnrichedSpans.CODE_BLOCK -> setCodeBlockStart(start) + EnrichedSpans.BLOCK_QUOTE -> setBlockQuoteStart(start) + EnrichedSpans.ORDERED_LIST -> setOrderedListStart(start) + EnrichedSpans.UNORDERED_LIST -> setUnorderedListStart(start) + EnrichedSpans.LINK -> setLinkStart(start) + EnrichedSpans.IMAGE -> setImageStart(start) + EnrichedSpans.MENTION -> setMentionStart(start) } } @@ -187,13 +187,13 @@ class EditorSpanState(private val editorView: EnrichedTextInputView) { merge(payload) } - val context = editorView.context as ReactContext + val context = view.context as ReactContext val surfaceId = UIManagerHelper.getSurfaceId(context) - val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, editorView.id) - dispatcher?.dispatchEvent(OnChangeStateEvent(surfaceId, editorView.id, payload)) + val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, view.id) + dispatcher?.dispatchEvent(OnChangeStateEvent(surfaceId, view.id, payload)) } companion object { - const val NAME = "ReactNativeRichTextEditorView" + const val NAME = "ReactNativeEnrichedView" } } diff --git a/android/src/main/java/com/swmansion/enriched/utils/EditorParser.java b/android/src/main/java/com/swmansion/enriched/utils/EnrichedParser.java similarity index 80% rename from android/src/main/java/com/swmansion/enriched/utils/EditorParser.java rename to android/src/main/java/com/swmansion/enriched/utils/EnrichedParser.java index e6be35d28..550774c97 100644 --- a/android/src/main/java/com/swmansion/enriched/utils/EditorParser.java +++ b/android/src/main/java/com/swmansion/enriched/utils/EnrichedParser.java @@ -10,26 +10,26 @@ import android.text.style.AlignmentSpan; import android.text.style.ParagraphStyle; -import com.swmansion.enriched.spans.EditorBlockQuoteSpan; -import com.swmansion.enriched.spans.EditorBoldSpan; -import com.swmansion.enriched.spans.EditorCodeBlockSpan; -import com.swmansion.enriched.spans.EditorH1Span; -import com.swmansion.enriched.spans.EditorH2Span; -import com.swmansion.enriched.spans.EditorH3Span; -import com.swmansion.enriched.spans.EditorImageSpan; -import com.swmansion.enriched.spans.EditorInlineCodeSpan; -import com.swmansion.enriched.spans.EditorItalicSpan; -import com.swmansion.enriched.spans.EditorLinkSpan; -import com.swmansion.enriched.spans.EditorMentionSpan; -import com.swmansion.enriched.spans.EditorOrderedListSpan; -import com.swmansion.enriched.spans.EditorStrikeThroughSpan; -import com.swmansion.enriched.spans.EditorUnderlineSpan; -import com.swmansion.enriched.spans.EditorUnorderedListSpan; -import com.swmansion.enriched.spans.interfaces.EditorBlockSpan; -import com.swmansion.enriched.spans.interfaces.EditorParagraphSpan; -import com.swmansion.enriched.spans.interfaces.EditorInlineSpan; -import com.swmansion.enriched.spans.interfaces.EditorZeroWidthSpaceSpan; -import com.swmansion.enriched.styles.RichTextStyle; +import com.swmansion.enriched.spans.EnrichedBlockQuoteSpan; +import com.swmansion.enriched.spans.EnrichedBoldSpan; +import com.swmansion.enriched.spans.EnrichedCodeBlockSpan; +import com.swmansion.enriched.spans.EnrichedH1Span; +import com.swmansion.enriched.spans.EnrichedH2Span; +import com.swmansion.enriched.spans.EnrichedH3Span; +import com.swmansion.enriched.spans.EnrichedImageSpan; +import com.swmansion.enriched.spans.EnrichedInlineCodeSpan; +import com.swmansion.enriched.spans.EnrichedItalicSpan; +import com.swmansion.enriched.spans.EnrichedLinkSpan; +import com.swmansion.enriched.spans.EnrichedMentionSpan; +import com.swmansion.enriched.spans.EnrichedOrderedListSpan; +import com.swmansion.enriched.spans.EnrichedStrikeThroughSpan; +import com.swmansion.enriched.spans.EnrichedUnderlineSpan; +import com.swmansion.enriched.spans.EnrichedUnorderedListSpan; +import com.swmansion.enriched.spans.interfaces.EnrichedBlockSpan; +import com.swmansion.enriched.spans.interfaces.EnrichedParagraphSpan; +import com.swmansion.enriched.spans.interfaces.EnrichedInlineSpan; +import com.swmansion.enriched.spans.interfaces.EnrichedZeroWidthSpaceSpan; +import com.swmansion.enriched.styles.HtmlStyle; import org.ccil.cowan.tagsoup.HTMLSchema; import org.ccil.cowan.tagsoup.Parser; @@ -51,7 +51,7 @@ * Most of the code in this file is copied from the Android source code and adjusted to our needs. * For the reference see docs */ -public class EditorParser { +public class EnrichedParser { /** * Retrieves images for HTML <img> tags. */ @@ -68,7 +68,7 @@ public interface ImageGetter { Drawable getDrawable(String source); } - private EditorParser() { } + private EnrichedParser() { } /** * Lazy initialization holder for HTML parser. This class will * a) be preloaded by the zygote, or b) not loaded until absolutely @@ -85,7 +85,7 @@ private static class HtmlParser { * *

This uses TagSoup to handle real HTML, including all of the brokenness found in the wild. */ - public static Spanned fromHtml(String source, RichTextStyle style, ImageGetter imageGetter) { + public static Spanned fromHtml(String source, HtmlStyle style, ImageGetter imageGetter) { Parser parser = new Parser(); try { parser.setProperty(Parser.schemaProperty, HtmlParser.schema); @@ -119,11 +119,11 @@ private static void withinHtml(StringBuilder out, Spanned text) { private static void withinDiv(StringBuilder out, Spanned text, int start, int end) { int next; for (int i = start; i < end; i = next) { - next = text.nextSpanTransition(i, end, EditorBlockSpan.class); - EditorBlockSpan[] blocks = text.getSpans(i, next, EditorBlockSpan.class); + next = text.nextSpanTransition(i, end, EnrichedBlockSpan.class); + EnrichedBlockSpan[] blocks = text.getSpans(i, next, EnrichedBlockSpan.class); String tag = "unknown"; if (blocks.length > 0){ - tag = blocks[0] instanceof EditorCodeBlockSpan ? "codeblock" : "blockquote"; + tag = blocks[0] instanceof EnrichedCodeBlockSpan ? "codeblock" : "blockquote"; } // Each block appends a newline by default. @@ -132,26 +132,26 @@ private static void withinDiv(StringBuilder out, Spanned text, int start, int en out.replace(out.length() - 5, out.length(), ""); } - for (EditorBlockSpan ignored : blocks) { + for (EnrichedBlockSpan ignored : blocks) { out.append("<").append(tag).append(">\n"); } withinBlock(out, text, i, next); - for (EditorBlockSpan ignored : blocks) { + for (EnrichedBlockSpan ignored : blocks) { out.append("\n"); } } } - private static String getBlockTag(EditorParagraphSpan[] spans) { - for (EditorParagraphSpan span : spans) { - if (span instanceof EditorUnorderedListSpan) { + private static String getBlockTag(EnrichedParagraphSpan[] spans) { + for (EnrichedParagraphSpan span : spans) { + if (span instanceof EnrichedUnorderedListSpan) { return "ul"; - } else if (span instanceof EditorOrderedListSpan) { + } else if (span instanceof EnrichedOrderedListSpan) { return "ol"; - } else if (span instanceof EditorH1Span) { + } else if (span instanceof EnrichedH1Span) { return "h1"; - } else if (span instanceof EditorH2Span) { + } else if (span instanceof EnrichedH2Span) { return "h2"; - } else if (span instanceof EditorH3Span) { + } else if (span instanceof EnrichedH3Span) { return "h3"; } } @@ -179,7 +179,7 @@ private static void withinBlock(StringBuilder out, Spanned text, int start, int } out.append("
\n"); } else { - EditorParagraphSpan[] paragraphStyles = text.getSpans(i, next, EditorParagraphSpan.class); + EnrichedParagraphSpan[] paragraphStyles = text.getSpans(i, next, EnrichedParagraphSpan.class); String tag = getBlockTag(paragraphStyles); boolean isUlListItem = tag.equals("ul"); boolean isOlListItem = tag.equals("ol"); @@ -229,39 +229,39 @@ private static void withinBlock(StringBuilder out, Spanned text, int start, int private static void withinParagraph(StringBuilder out, Spanned text, int start, int end) { int next; for (int i = start; i < end; i = next) { - next = text.nextSpanTransition(i, end, EditorInlineSpan.class); - EditorInlineSpan[] style = text.getSpans(i, next, EditorInlineSpan.class); + next = text.nextSpanTransition(i, end, EnrichedInlineSpan.class); + EnrichedInlineSpan[] style = text.getSpans(i, next, EnrichedInlineSpan.class); for (int j = 0; j < style.length; j++) { - if (style[j] instanceof EditorBoldSpan) { + if (style[j] instanceof EnrichedBoldSpan) { out.append(""); } - if (style[j] instanceof EditorItalicSpan) { + if (style[j] instanceof EnrichedItalicSpan) { out.append(""); } - if (style[j] instanceof EditorUnderlineSpan) { + if (style[j] instanceof EnrichedUnderlineSpan) { out.append(""); } - if (style[j] instanceof EditorInlineCodeSpan) { + if (style[j] instanceof EnrichedInlineCodeSpan) { out.append(""); } - if (style[j] instanceof EditorStrikeThroughSpan) { + if (style[j] instanceof EnrichedStrikeThroughSpan) { out.append(""); } - if (style[j] instanceof EditorLinkSpan) { + if (style[j] instanceof EnrichedLinkSpan) { out.append(""); } - if (style[j] instanceof EditorMentionSpan) { + if (style[j] instanceof EnrichedMentionSpan) { out.append(" attributes = ((EditorMentionSpan) style[j]).getAttributes(); + Map attributes = ((EnrichedMentionSpan) style[j]).getAttributes(); for (Map.Entry entry : attributes.entrySet()) { out.append(" "); out.append(entry.getKey()); @@ -272,9 +272,9 @@ private static void withinParagraph(StringBuilder out, Spanned text, int start, out.append(">"); } - if (style[j] instanceof EditorImageSpan) { + if (style[j] instanceof EnrichedImageSpan) { out.append(""); // Don't output the placeholder character underlying the image. i = next; @@ -282,25 +282,25 @@ private static void withinParagraph(StringBuilder out, Spanned text, int start, } withinStyle(out, text, i, next); for (int j = style.length - 1; j >= 0; j--) { - if (style[j] instanceof EditorLinkSpan) { + if (style[j] instanceof EnrichedLinkSpan) { out.append(""); } - if (style[j] instanceof EditorMentionSpan) { + if (style[j] instanceof EnrichedMentionSpan) { out.append(""); } - if (style[j] instanceof EditorStrikeThroughSpan) { + if (style[j] instanceof EnrichedStrikeThroughSpan) { out.append(""); } - if (style[j] instanceof EditorUnderlineSpan) { + if (style[j] instanceof EnrichedUnderlineSpan) { out.append(""); } - if (style[j] instanceof EditorInlineCodeSpan) { + if (style[j] instanceof EnrichedInlineCodeSpan) { out.append(""); } - if (style[j] instanceof EditorBoldSpan) { + if (style[j] instanceof EnrichedBoldSpan) { out.append(""); } - if (style[j] instanceof EditorItalicSpan) { + if (style[j] instanceof EnrichedItalicSpan) { out.append(""); } } @@ -343,15 +343,15 @@ private static void withinStyle(StringBuilder out, CharSequence text, } } class HtmlToSpannedConverter implements ContentHandler { - private final RichTextStyle mStyle; + private final HtmlStyle mStyle; private final String mSource; private final XMLReader mReader; private final SpannableStringBuilder mSpannableStringBuilder; - private final EditorParser.ImageGetter mImageGetter; + private final EnrichedParser.ImageGetter mImageGetter; private static Integer currentOrderedListItemIndex = 0; private static Boolean isInOrderedList = false; - public HtmlToSpannedConverter(String source, RichTextStyle style, EditorParser.ImageGetter imageGetter, Parser parser) { + public HtmlToSpannedConverter(String source, HtmlStyle style, EnrichedParser.ImageGetter imageGetter, Parser parser) { mStyle = style; mSource = source; mSpannableStringBuilder = new SpannableStringBuilder(); @@ -392,8 +392,8 @@ public Spanned convert() { } // Assign zero-width space character to the proper spans. - EditorZeroWidthSpaceSpan[] zeroWidthSpaceSpans = mSpannableStringBuilder.getSpans(0, mSpannableStringBuilder.length(), EditorZeroWidthSpaceSpan.class); - for (EditorZeroWidthSpaceSpan zeroWidthSpaceSpan : zeroWidthSpaceSpans) { + EnrichedZeroWidthSpaceSpan[] zeroWidthSpaceSpans = mSpannableStringBuilder.getSpans(0, mSpannableStringBuilder.length(), EnrichedZeroWidthSpaceSpan.class); + for (EnrichedZeroWidthSpaceSpan zeroWidthSpaceSpan : zeroWidthSpaceSpans) { int start = mSpannableStringBuilder.getSpanStart(zeroWidthSpaceSpan); int end = mSpannableStringBuilder.getSpanEnd(zeroWidthSpaceSpan); mSpannableStringBuilder.insert(start, "\u200B"); @@ -460,9 +460,9 @@ private void handleEndTag(String tag) { } else if (tag.equalsIgnoreCase("li")) { endLi(mSpannableStringBuilder, mStyle); } else if (tag.equalsIgnoreCase("b")) { - end(mSpannableStringBuilder, Bold.class, new EditorBoldSpan(mStyle)); + end(mSpannableStringBuilder, Bold.class, new EnrichedBoldSpan(mStyle)); } else if (tag.equalsIgnoreCase("i")) { - end(mSpannableStringBuilder, Italic.class, new EditorItalicSpan(mStyle)); + end(mSpannableStringBuilder, Italic.class, new EnrichedItalicSpan(mStyle)); } else if (tag.equalsIgnoreCase("blockquote")) { endBlockquote(mSpannableStringBuilder, mStyle); } else if (tag.equalsIgnoreCase("codeblock")) { @@ -470,9 +470,9 @@ private void handleEndTag(String tag) { } else if (tag.equalsIgnoreCase("a")) { endA(mSpannableStringBuilder, mStyle); } else if (tag.equalsIgnoreCase("u")) { - end(mSpannableStringBuilder, Underline.class, new EditorUnderlineSpan(mStyle)); + end(mSpannableStringBuilder, Underline.class, new EnrichedUnderlineSpan(mStyle)); } else if (tag.equalsIgnoreCase("s")) { - end(mSpannableStringBuilder, Strikethrough.class, new EditorStrikeThroughSpan(mStyle)); + end(mSpannableStringBuilder, Strikethrough.class, new EnrichedStrikeThroughSpan(mStyle)); } else if (tag.equalsIgnoreCase("h1")) { endHeading(mSpannableStringBuilder, mStyle, 1); } else if (tag.equalsIgnoreCase("h2")) { @@ -480,7 +480,7 @@ private void handleEndTag(String tag) { } else if (tag.equalsIgnoreCase("h3")) { endHeading(mSpannableStringBuilder, mStyle, 3); } else if (tag.equalsIgnoreCase("code")) { - end(mSpannableStringBuilder, Code.class, new EditorInlineCodeSpan(mStyle)); + end(mSpannableStringBuilder, Code.class, new EnrichedInlineCodeSpan(mStyle)); } else if (tag.equalsIgnoreCase("mention")) { endMention(mSpannableStringBuilder, mStyle); } @@ -532,15 +532,15 @@ private void startLi(Editable text) { } } - private static void endLi(Editable text, RichTextStyle style) { + private static void endLi(Editable text, HtmlStyle style) { endBlockElement(text); List l = getLast(text, List.class); if (l != null) { if (l.mType.equals("ol")) { - setParagraphSpanFromMark(text, l, new EditorOrderedListSpan(l.mIndex, style)); + setParagraphSpanFromMark(text, l, new EnrichedOrderedListSpan(l.mIndex, style)); } else { - setParagraphSpanFromMark(text, l, new EditorUnorderedListSpan(style)); + setParagraphSpanFromMark(text, l, new EnrichedUnorderedListSpan(style)); } } @@ -552,10 +552,10 @@ private void startBlockquote(Editable text) { start(text, new Blockquote()); } - private static void endBlockquote(Editable text, RichTextStyle style) { + private static void endBlockquote(Editable text, HtmlStyle style) { endBlockElement(text); Blockquote last = getLast(text, Blockquote.class); - setParagraphSpanFromMark(text, last, new EditorBlockQuoteSpan(style)); + setParagraphSpanFromMark(text, last, new EnrichedBlockQuoteSpan(style)); } private void startCodeBlock(Editable text) { @@ -563,10 +563,10 @@ private void startCodeBlock(Editable text) { start(text, new CodeBlock()); } - private static void endCodeBlock(Editable text, RichTextStyle style) { + private static void endCodeBlock(Editable text, HtmlStyle style) { endBlockElement(text); CodeBlock last = getLast(text, CodeBlock.class); - setParagraphSpanFromMark(text, last, new EditorCodeBlockSpan(style)); + setParagraphSpanFromMark(text, last, new EnrichedCodeBlockSpan(style)); } private void startHeading(Editable text, int level) { @@ -587,21 +587,21 @@ private void startHeading(Editable text, int level) { } } - private static void endHeading(Editable text, RichTextStyle style, int level) { + private static void endHeading(Editable text, HtmlStyle style, int level) { endBlockElement(text); switch (level) { case 1: H1 lastH1 = getLast(text, H1.class); - setParagraphSpanFromMark(text, lastH1, new EditorH1Span(style)); + setParagraphSpanFromMark(text, lastH1, new EnrichedH1Span(style)); break; case 2: H2 lastH2 = getLast(text, H2.class); - setParagraphSpanFromMark(text, lastH2, new EditorH2Span(style)); + setParagraphSpanFromMark(text, lastH2, new EnrichedH2Span(style)); break; case 3: H3 lastH3 = getLast(text, H3.class); - setParagraphSpanFromMark(text, lastH3, new EditorH3Span(style)); + setParagraphSpanFromMark(text, lastH3, new EnrichedH3Span(style)); break; default: throw new IllegalArgumentException("Unsupported heading level: " + level); @@ -661,7 +661,7 @@ private static void end(Editable text, Class kind, Object repl) { } } - private static void startImg(Editable text, Attributes attributes, EditorParser.ImageGetter img, RichTextStyle style) { + private static void startImg(Editable text, Attributes attributes, EnrichedParser.ImageGetter img, HtmlStyle style) { String src = attributes.getValue("", "src"); Drawable d = null; if (img != null) { @@ -674,7 +674,7 @@ private static void startImg(Editable text, Attributes attributes, EditorParser. int len = text.length(); text.append(""); - text.setSpan(new EditorImageSpan(d, src, style), len, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + text.setSpan(new EnrichedImageSpan(d, src, style), len, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } private static void startA(Editable text, Attributes attributes) { @@ -682,11 +682,11 @@ private static void startA(Editable text, Attributes attributes) { start(text, new Href(href)); } - private void endA(Editable text, RichTextStyle style) { + private void endA(Editable text, HtmlStyle style) { Href h = getLast(text, Href.class); if (h != null) { if (h.mHref != null) { - setSpanFromMark(text, h, new EditorLinkSpan(h.mHref, style)); + setSpanFromMark(text, h, new EnrichedLinkSpan(h.mHref, style)); } } } @@ -707,13 +707,13 @@ private static void startMention(Editable mention, Attributes attributes) { start(mention, new Mention(indicator, text, attributesMap)); } - private void endMention(Editable text, RichTextStyle style) { + private void endMention(Editable text, HtmlStyle style) { Mention m = getLast(text, Mention.class); if (m == null) return; if (m.mText == null) return; - setSpanFromMark(text, m, new EditorMentionSpan(m.mText, m.mIndicator, m.mAttributes, style)); + setSpanFromMark(text, m, new EnrichedMentionSpan(m.mText, m.mIndicator, m.mAttributes, style)); } public void setDocumentLocator(Locator locator) { diff --git a/android/src/main/java/com/swmansion/enriched/utils/Utils.kt b/android/src/main/java/com/swmansion/enriched/utils/Utils.kt index 25d0ff4fc..cd7c9c8c9 100644 --- a/android/src/main/java/com/swmansion/enriched/utils/Utils.kt +++ b/android/src/main/java/com/swmansion/enriched/utils/Utils.kt @@ -4,8 +4,8 @@ import android.text.Spannable import android.text.SpannableString import android.text.SpannableStringBuilder import android.util.Log -import com.swmansion.enriched.spans.interfaces.EditorBlockSpan -import com.swmansion.enriched.spans.interfaces.EditorParagraphSpan +import com.swmansion.enriched.spans.interfaces.EnrichedBlockSpan +import com.swmansion.enriched.spans.interfaces.EnrichedParagraphSpan import org.json.JSONObject fun jsonStringToStringMap(json: String): Map { @@ -19,7 +19,7 @@ fun jsonStringToStringMap(json: String): Map { } } } catch (e: Exception) { - Log.w("ReactNativeRichTextEditorView", "Failed to parse JSON string to Map: $json", e) + Log.w("ReactNativeEnrichedView", "Failed to parse JSON string to Map: $json", e) } return result @@ -67,10 +67,10 @@ fun Spannable.mergeSpannables(start: Int, end: Int, spannable: Spannable): Spann var finalEnd = end val builder = SpannableStringBuilder(this) - val startBlockSpans = spannable.getSpans(0, 0, EditorBlockSpan::class.java) - val startParagraphSpans = spannable.getSpans(0, 0, EditorParagraphSpan::class.java) - val endBlockSpans = spannable.getSpans(this.length, this.length, EditorBlockSpan::class.java) - val endParagraphSpans = spannable.getSpans(this.length, this.length, EditorParagraphSpan::class.java) + val startBlockSpans = spannable.getSpans(0, 0, EnrichedBlockSpan::class.java) + val startParagraphSpans = spannable.getSpans(0, 0, EnrichedParagraphSpan::class.java) + val endBlockSpans = spannable.getSpans(this.length, this.length, EnrichedBlockSpan::class.java) + val endParagraphSpans = spannable.getSpans(this.length, this.length, EnrichedParagraphSpan::class.java) val (paragraphStart, paragraphEnd) = this.getParagraphBounds(start, end) val isNewLineStart = startBlockSpans.isNotEmpty() || startParagraphSpans.isNotEmpty() val isNewLineEnd = endBlockSpans.isNotEmpty() || endParagraphSpans.isNotEmpty() diff --git a/android/src/main/java/com/swmansion/enriched/watchers/EditorSpanWatcher.kt b/android/src/main/java/com/swmansion/enriched/watchers/EnrichedSpanWatcher.kt similarity index 71% rename from android/src/main/java/com/swmansion/enriched/watchers/EditorSpanWatcher.kt rename to android/src/main/java/com/swmansion/enriched/watchers/EnrichedSpanWatcher.kt index 4a9f50b28..b304816a6 100644 --- a/android/src/main/java/com/swmansion/enriched/watchers/EditorSpanWatcher.kt +++ b/android/src/main/java/com/swmansion/enriched/watchers/EnrichedSpanWatcher.kt @@ -7,13 +7,13 @@ import com.facebook.react.bridge.ReactContext import com.facebook.react.uimanager.UIManagerHelper import com.swmansion.enriched.EnrichedTextInputView import com.swmansion.enriched.events.OnChangeHtmlEvent -import com.swmansion.enriched.spans.EditorOrderedListSpan -import com.swmansion.enriched.spans.interfaces.EditorHeadingSpan -import com.swmansion.enriched.spans.interfaces.EditorSpan -import com.swmansion.enriched.utils.EditorParser +import com.swmansion.enriched.spans.EnrichedOrderedListSpan +import com.swmansion.enriched.spans.interfaces.EnrichedHeadingSpan +import com.swmansion.enriched.spans.interfaces.EnrichedSpan +import com.swmansion.enriched.utils.EnrichedParser import com.swmansion.enriched.utils.getSafeSpanBoundaries -class EditorSpanWatcher(private val editorView: EnrichedTextInputView) : SpanWatcher { +class EnrichedSpanWatcher(private val view: EnrichedTextInputView) : SpanWatcher { private var previousHtml: String? = null override fun onSpanAdded(text: Spannable, what: Any, start: Int, end: Int) { @@ -33,8 +33,8 @@ class EditorSpanWatcher(private val editorView: EnrichedTextInputView) : SpanWat } private fun updateUnorderedListSpans(what: Any, text: Spannable, end: Int) { - if (what is EditorOrderedListSpan) { - editorView.listStyles?.updateOrderedListIndexes(text, end) + if (what is EnrichedOrderedListSpan) { + view.listStyles?.updateOrderedListIndexes(text, end) } } @@ -43,7 +43,7 @@ class EditorSpanWatcher(private val editorView: EnrichedTextInputView) : SpanWat private fun updateNextLineLayout(what: Any, text: Spannable, end: Int) { class EmptySpan : ParagraphStyle {} - if (what is EditorHeadingSpan) { + if (what is EnrichedHeadingSpan) { val finalStart = (end + 1) val finalEnd = text.length val (safeStart, safeEnd) = text.getSafeSpanBoundaries(finalStart, finalEnd) @@ -53,16 +53,16 @@ class EditorSpanWatcher(private val editorView: EnrichedTextInputView) : SpanWat fun emitEvent(s: Spannable, what: Any?) { // Emit event only if we change one of ours spans - if (what != null && what !is EditorSpan) return + if (what != null && what !is EnrichedSpan) return - val html = EditorParser.toHtml(s) + val html = EnrichedParser.toHtml(s) if (html == previousHtml) return previousHtml = html - editorView.layoutManager.invalidateLayout(editorView.text) - val context = editorView.context as ReactContext + view.layoutManager.invalidateLayout(view.text) + val context = view.context as ReactContext val surfaceId = UIManagerHelper.getSurfaceId(context) - val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, editorView.id) - dispatcher?.dispatchEvent(OnChangeHtmlEvent(surfaceId, editorView.id, html)) + val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, view.id) + dispatcher?.dispatchEvent(OnChangeHtmlEvent(surfaceId, view.id, html)) } } diff --git a/android/src/main/java/com/swmansion/enriched/watchers/EditorTextWatcher.kt b/android/src/main/java/com/swmansion/enriched/watchers/EnrichedTextWatcher.kt similarity index 55% rename from android/src/main/java/com/swmansion/enriched/watchers/EditorTextWatcher.kt rename to android/src/main/java/com/swmansion/enriched/watchers/EnrichedTextWatcher.kt index 32236aefa..d22fdd9cf 100644 --- a/android/src/main/java/com/swmansion/enriched/watchers/EditorTextWatcher.kt +++ b/android/src/main/java/com/swmansion/enriched/watchers/EnrichedTextWatcher.kt @@ -7,7 +7,7 @@ import com.facebook.react.uimanager.UIManagerHelper import com.swmansion.enriched.EnrichedTextInputView import com.swmansion.enriched.events.OnChangeTextEvent -class EditorTextWatcher(private val editorView: EnrichedTextInputView) : TextWatcher { +class EnrichedTextWatcher(private val view: EnrichedTextInputView) : TextWatcher { private var endCursorPosition: Int = 0 private var previousTextLength: Int = 0 @@ -17,30 +17,30 @@ class EditorTextWatcher(private val editorView: EnrichedTextInputView) : TextWat override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { endCursorPosition = start + count - editorView.layoutManager.measureSize(s ?: "") - editorView.isRemovingMany = !editorView.isSettingValue && before > count + 1 + view.layoutManager.measureSize(s ?: "") + view.isRemovingMany = !view.isSettingValue && before > count + 1 } override fun afterTextChanged(s: Editable?) { if (s == null) return emitEvents(s) - if (editorView.isSettingValue) return + if (view.isSettingValue) return applyStyles(s) } private fun applyStyles(s: Editable) { - editorView.inlineStyles?.afterTextChanged(s, endCursorPosition) - editorView.paragraphStyles?.afterTextChanged(s, endCursorPosition, previousTextLength) - editorView.listStyles?.afterTextChanged(s, endCursorPosition, previousTextLength) - editorView.parametrizedStyles?.afterTextChanged(s, endCursorPosition) + view.inlineStyles?.afterTextChanged(s, endCursorPosition) + view.paragraphStyles?.afterTextChanged(s, endCursorPosition, previousTextLength) + view.listStyles?.afterTextChanged(s, endCursorPosition, previousTextLength) + view.parametrizedStyles?.afterTextChanged(s, endCursorPosition) } private fun emitEvents(s: Editable) { - val context = editorView.context as ReactContext + val context = view.context as ReactContext val surfaceId = UIManagerHelper.getSurfaceId(context) - val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, editorView.id) - dispatcher?.dispatchEvent(OnChangeTextEvent(surfaceId, editorView.id, s)) - editorView.spanWatcher?.emitEvent(s, null) + val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, view.id) + dispatcher?.dispatchEvent(OnChangeTextEvent(surfaceId, view.id, s)) + view.spanWatcher?.emitEvent(s, null) } } From d614384b6b48c99b2bfeefd1cff92c3717103a0a Mon Sep 17 00:00:00 2001 From: szydlovsky <9szydlowski9@gmail.com> Date: Fri, 29 Aug 2025 15:03:07 +0200 Subject: [PATCH 3/8] chore: initial iOS renaming --- ...tor.podspec => ReactNativeEnriched.podspec | 2 +- example/ios/Podfile.lock | 8 +- .../project.pbxproj | 64 +++--- ...xtEditorView.h => EnrichedTextInputView.h} | 20 +- ...EditorView.mm => EnrichedTextInputView.mm} | 188 +++++++++--------- ios/EnrichedTextInputViewManager.mm | 13 ++ ios/ReactNativeRichTextEditorViewManager.mm | 13 -- ios/config/{EditorConfig.h => InputConfig.h} | 2 +- .../{EditorConfig.mm => InputConfig.mm} | 6 +- ios/editorTextView/EditorTextView.h | 6 - .../InputParser.h} | 4 +- .../InputParser.mm} | 50 ++--- ios/inputTextView/InputTextView.h | 6 + .../InputTextView.mm} | 48 ++--- ...nrichedTextInputViewComponentDescriptor.h} | 8 +- .../EnrichedTextInputViewShadowNode.h | 40 ++++ ....mm => EnrichedTextInputViewShadowNode.mm} | 18 +- ios/internals/EnrichedTextInputViewState.cpp | 10 + ...ewState.h => EnrichedTextInputViewState.h} | 6 +- .../ReactNativeRichTextEditorViewShadowNode.h | 40 ---- .../ReactNativeRichTextEditorViewState.cpp | 10 - ios/styles/BlockQuoteStyle.mm | 96 ++++----- ios/styles/BoldStyle.mm | 52 ++--- ios/styles/H1Style.mm | 6 +- ios/styles/H2Style.mm | 6 +- ios/styles/H3Style.mm | 6 +- ios/styles/HeadingStyleBase.mm | 54 ++--- ios/styles/InlineCodeStyle.mm | 90 ++++----- ios/styles/ItalicStyle.mm | 44 ++-- ios/styles/LinkStyle.mm | 184 ++++++++--------- ios/styles/MentionStyle.mm | 162 +++++++-------- ios/styles/OrderedListStyle.mm | 88 ++++---- ios/styles/StrikethroughStyle.mm | 28 +-- ios/styles/UnderlineStyle.mm | 38 ++-- ios/styles/UnorderedListStyle.mm | 88 ++++---- ios/utils/BaseStyleProtocol.h | 2 +- ios/utils/FontExtension.h | 1 - ios/utils/FontExtension.mm | 10 +- ios/utils/LayoutManagerExtension.h | 2 +- ios/utils/LayoutManagerExtension.mm | 58 +++--- ios/utils/MentionStyleProps.mm | 1 - ios/utils/OccurenceUtils.h | 14 +- ios/utils/OccurenceUtils.mm | 24 +-- ios/utils/StyleHeaders.h | 2 +- ios/utils/TextInsertionUtils.h | 4 +- ios/utils/TextInsertionUtils.mm | 22 +- ios/utils/ZeroWidthSpaceUtils.h | 4 +- ios/utils/ZeroWidthSpaceUtils.mm | 92 +++++---- 48 files changed, 871 insertions(+), 869 deletions(-) rename ReactNativeRichTextEditor.podspec => ReactNativeEnriched.podspec (95%) rename ios/{ReactNativeRichTextEditorView.h => EnrichedTextInputView.h} (64%) rename ios/{ReactNativeRichTextEditorView.mm => EnrichedTextInputView.mm} (86%) create mode 100644 ios/EnrichedTextInputViewManager.mm delete mode 100644 ios/ReactNativeRichTextEditorViewManager.mm rename ios/config/{EditorConfig.h => InputConfig.h} (98%) rename ios/config/{EditorConfig.mm => InputConfig.mm} (98%) delete mode 100644 ios/editorTextView/EditorTextView.h rename ios/{parser/EditorParser.h => inputParser/InputParser.h} (79%) rename ios/{parser/EditorParser.mm => inputParser/InputParser.mm} (94%) create mode 100644 ios/inputTextView/InputTextView.h rename ios/{editorTextView/EditorTextView.mm => inputTextView/InputTextView.mm} (62%) rename ios/internals/{ReactNativeRichTextEditorViewComponentDescriptor.h => EnrichedTextInputViewComponentDescriptor.h} (51%) create mode 100644 ios/internals/EnrichedTextInputViewShadowNode.h rename ios/internals/{ReactNativeRichTextEditorViewShadowNode.mm => EnrichedTextInputViewShadowNode.mm} (77%) create mode 100644 ios/internals/EnrichedTextInputViewState.cpp rename ios/internals/{ReactNativeRichTextEditorViewState.h => EnrichedTextInputViewState.h} (62%) delete mode 100644 ios/internals/ReactNativeRichTextEditorViewShadowNode.h delete mode 100644 ios/internals/ReactNativeRichTextEditorViewState.cpp diff --git a/ReactNativeRichTextEditor.podspec b/ReactNativeEnriched.podspec similarity index 95% rename from ReactNativeRichTextEditor.podspec rename to ReactNativeEnriched.podspec index ec1d8da9a..83ec29777 100644 --- a/ReactNativeRichTextEditor.podspec +++ b/ReactNativeEnriched.podspec @@ -3,7 +3,7 @@ require "json" package = JSON.parse(File.read(File.join(__dir__, "package.json"))) Pod::Spec.new do |s| - s.name = "ReactNativeRichTextEditor" + s.name = "ReactNativeEnriched" s.version = package["version"] s.summary = package["description"] s.homepage = package["homepage"] diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 55c31ba87..8889c5e97 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -2251,7 +2251,7 @@ PODS: - React-perflogger (= 0.81.0) - React-utils (= 0.81.0) - SocketRocket - - ReactNativeRichTextEditor (0.1.0): + - ReactNativeEnriched (0.1.0): - boost - DoubleConversion - fast_float @@ -2355,7 +2355,7 @@ DEPENDENCIES: - ReactAppDependencyProvider (from `build/generated/ios`) - ReactCodegen (from `build/generated/ios`) - ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`) - - ReactNativeRichTextEditor (from `../..`) + - ReactNativeEnriched (from `../..`) - SocketRocket (~> 0.7.1) - Yoga (from `../node_modules/react-native/ReactCommon/yoga`) @@ -2507,7 +2507,7 @@ EXTERNAL SOURCES: :path: build/generated/ios ReactCommon: :path: "../node_modules/react-native/ReactCommon" - ReactNativeRichTextEditor: + ReactNativeEnriched: :path: "../.." Yoga: :path: "../node_modules/react-native/ReactCommon/yoga" @@ -2584,7 +2584,7 @@ SPEC CHECKSUMS: ReactAppDependencyProvider: 562d731311d0524a577cf8a01faa97874bacbdfe ReactCodegen: a5d5626f71299d374b87e9a7dc92f968a963b4ef ReactCommon: c235ebd26d63fde9a2dfa72cee9f8294b910fee1 - ReactNativeRichTextEditor: fca76141711f42ba23278cc8ad3bf396057eed44 + ReactNativeEnriched: 9600491c8cc937f20a4d90c155b8febb1b6925b1 SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748 Yoga: b01392348aeea02064c21a2762a42893d82b60a7 diff --git a/example/ios/ReactNativeRichTextEditorExample.xcodeproj/project.pbxproj b/example/ios/ReactNativeRichTextEditorExample.xcodeproj/project.pbxproj index 69c113344..85a6fc56f 100644 --- a/example/ios/ReactNativeRichTextEditorExample.xcodeproj/project.pbxproj +++ b/example/ios/ReactNativeRichTextEditorExample.xcodeproj/project.pbxproj @@ -26,9 +26,9 @@ 907A3D37EC6F4B9DA1B70348 /* CascadiaCode-ExtraLight.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 4A13A7631B3C499C989AC38A /* CascadiaCode-ExtraLight.ttf */; }; 95A487B0B0A94AFDA7B10C06 /* FontAwesome.ttf in Resources */ = {isa = PBXBuildFile; fileRef = D133E950DA6A4BC0A97DDFFE /* FontAwesome.ttf */; }; 970142F6180042E5964006A6 /* CascadiaCode-Light.ttf in Resources */ = {isa = PBXBuildFile; fileRef = DA76D9192FE24EC28C84DE79 /* CascadiaCode-Light.ttf */; }; + A988CCBE7099E5FBB91D5392 /* libPods-ReactNativeRichTextEditorExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 594377F3FC79DF09B28DA8C3 /* libPods-ReactNativeRichTextEditorExample.a */; }; D8B2038262614F14AE6245F0 /* CascadiaCode-SemiBoldItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 4DA2D2AB9E3743888DAD5779 /* CascadiaCode-SemiBoldItalic.ttf */; }; DCB0457B1CAE40B29979CDB9 /* CascadiaCode-VariableFont_wght.ttf in Resources */ = {isa = PBXBuildFile; fileRef = D384E64346204A8C8E773595 /* CascadiaCode-VariableFont_wght.ttf */; }; - E6AE3E75AAB6AEA81E4636B6 /* libPods-ReactNativeRichTextEditorExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1BE313EFA3DE90E22B2A2BB6 /* libPods-ReactNativeRichTextEditorExample.a */; }; F83E68A3773947EA87D1FD9C /* CascadiaCode-SemiBold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 3FD646A3FF0F4F33AC65021F /* CascadiaCode-SemiBold.ttf */; }; /* End PBXBuildFile section */ @@ -37,13 +37,13 @@ 13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = ReactNativeRichTextEditorExample/Images.xcassets; sourceTree = ""; }; 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = ReactNativeRichTextEditorExample/Info.plist; sourceTree = ""; }; 13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = PrivacyInfo.xcprivacy; path = ReactNativeRichTextEditorExample/PrivacyInfo.xcprivacy; sourceTree = ""; }; - 1BE313EFA3DE90E22B2A2BB6 /* libPods-ReactNativeRichTextEditorExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ReactNativeRichTextEditorExample.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - 30BAB32B24F7542D489838C7 /* Pods-ReactNativeRichTextEditorExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeRichTextEditorExample.release.xcconfig"; path = "Target Support Files/Pods-ReactNativeRichTextEditorExample/Pods-ReactNativeRichTextEditorExample.release.xcconfig"; sourceTree = ""; }; 3A18DEB91C24449AA3ECE59A /* CascadiaCode-Italic-VariableFont_wght.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-Italic-VariableFont_wght.ttf"; path = "../assets/fonts/Cascadia_Code/CascadiaCode-Italic-VariableFont_wght.ttf"; sourceTree = ""; }; + 3C13A583FC86796D0F36DF7C /* Pods-ReactNativeRichTextEditorExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeRichTextEditorExample.release.xcconfig"; path = "Target Support Files/Pods-ReactNativeRichTextEditorExample/Pods-ReactNativeRichTextEditorExample.release.xcconfig"; sourceTree = ""; }; 3FD646A3FF0F4F33AC65021F /* CascadiaCode-SemiBold.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-SemiBold.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-SemiBold.ttf"; sourceTree = ""; }; 4A13A7631B3C499C989AC38A /* CascadiaCode-ExtraLight.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-ExtraLight.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-ExtraLight.ttf"; sourceTree = ""; }; 4DA2D2AB9E3743888DAD5779 /* CascadiaCode-SemiBoldItalic.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-SemiBoldItalic.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-SemiBoldItalic.ttf"; sourceTree = ""; }; 4E36300E55D4493B9BE898E6 /* CascadiaCode-Regular.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-Regular.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-Regular.ttf"; sourceTree = ""; }; + 594377F3FC79DF09B28DA8C3 /* libPods-ReactNativeRichTextEditorExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ReactNativeRichTextEditorExample.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 5D1BB596339A4F8E8CBC2087 /* CascadiaCode-BoldItalic.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-BoldItalic.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-BoldItalic.ttf"; sourceTree = ""; }; 6352E13F84F841D5A2BA25B4 /* CascadiaCode-Italic.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-Italic.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-Italic.ttf"; sourceTree = ""; }; 674C8E7598D647768ECEC0E1 /* OFL.txt */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = OFL.txt; path = ../assets/fonts/Cascadia_Code/OFL.txt; sourceTree = ""; }; @@ -56,10 +56,10 @@ 87375222174145AD85B4DE62 /* CascadiaCode-Medium.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-Medium.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-Medium.ttf"; sourceTree = ""; }; 8A425B9B75B9488EA0FDF624 /* README.txt */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = README.txt; path = ../assets/fonts/Cascadia_Code/README.txt; sourceTree = ""; }; C667157990F34428AEE8CC93 /* FontAwesome.json */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = FontAwesome.json; path = ../assets/icons/FontAwesome.json; sourceTree = ""; }; - CE2992D25A1E9E45E24B984C /* Pods-ReactNativeRichTextEditorExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeRichTextEditorExample.debug.xcconfig"; path = "Target Support Files/Pods-ReactNativeRichTextEditorExample/Pods-ReactNativeRichTextEditorExample.debug.xcconfig"; sourceTree = ""; }; D133E950DA6A4BC0A97DDFFE /* FontAwesome.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = FontAwesome.ttf; path = ../assets/icons/FontAwesome.ttf; sourceTree = ""; }; D384E64346204A8C8E773595 /* CascadiaCode-VariableFont_wght.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-VariableFont_wght.ttf"; path = "../assets/fonts/Cascadia_Code/CascadiaCode-VariableFont_wght.ttf"; sourceTree = ""; }; DA76D9192FE24EC28C84DE79 /* CascadiaCode-Light.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-Light.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-Light.ttf"; sourceTree = ""; }; + E6A46588CE906F8A9AC9DB45 /* Pods-ReactNativeRichTextEditorExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeRichTextEditorExample.debug.xcconfig"; path = "Target Support Files/Pods-ReactNativeRichTextEditorExample/Pods-ReactNativeRichTextEditorExample.debug.xcconfig"; sourceTree = ""; }; ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; /* End PBXFileReference section */ @@ -68,7 +68,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - E6AE3E75AAB6AEA81E4636B6 /* libPods-ReactNativeRichTextEditorExample.a in Frameworks */, + A988CCBE7099E5FBB91D5392 /* libPods-ReactNativeRichTextEditorExample.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -91,7 +91,7 @@ isa = PBXGroup; children = ( ED297162215061F000B7C4FE /* JavaScriptCore.framework */, - 1BE313EFA3DE90E22B2A2BB6 /* libPods-ReactNativeRichTextEditorExample.a */, + 594377F3FC79DF09B28DA8C3 /* libPods-ReactNativeRichTextEditorExample.a */, ); name = Frameworks; sourceTree = ""; @@ -129,8 +129,8 @@ BBD78D7AC51CEA395F1C20DB /* Pods */ = { isa = PBXGroup; children = ( - CE2992D25A1E9E45E24B984C /* Pods-ReactNativeRichTextEditorExample.debug.xcconfig */, - 30BAB32B24F7542D489838C7 /* Pods-ReactNativeRichTextEditorExample.release.xcconfig */, + E6A46588CE906F8A9AC9DB45 /* Pods-ReactNativeRichTextEditorExample.debug.xcconfig */, + 3C13A583FC86796D0F36DF7C /* Pods-ReactNativeRichTextEditorExample.release.xcconfig */, ); path = Pods; sourceTree = ""; @@ -168,13 +168,13 @@ isa = PBXNativeTarget; buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "ReactNativeRichTextEditorExample" */; buildPhases = ( - E8E8B1D71189538899D5EDEB /* [CP] Check Pods Manifest.lock */, + 69C011D95EDBCACAB3FC1113 /* [CP] Check Pods Manifest.lock */, 13B07F871A680F5B00A75B9A /* Sources */, 13B07F8C1A680F5B00A75B9A /* Frameworks */, 13B07F8E1A680F5B00A75B9A /* Resources */, 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */, - E37ABD7431ADE223A4A33FE5 /* [CP] Embed Pods Frameworks */, - 89ACA76C9F1E435BFBFA61A5 /* [CP] Copy Pods Resources */, + 53EBC749589386D90FE2E60D /* [CP] Embed Pods Frameworks */, + B1576F9548D80B049BBF8E31 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -264,24 +264,7 @@ shellPath = /bin/sh; shellScript = "set -e\n\nWITH_ENVIRONMENT=\"$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"$REACT_NATIVE_PATH/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n"; }; - 89ACA76C9F1E435BFBFA61A5 /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-ReactNativeRichTextEditorExample/Pods-ReactNativeRichTextEditorExample-resources-${CONFIGURATION}-input-files.xcfilelist", - ); - name = "[CP] Copy Pods Resources"; - outputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-ReactNativeRichTextEditorExample/Pods-ReactNativeRichTextEditorExample-resources-${CONFIGURATION}-output-files.xcfilelist", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-ReactNativeRichTextEditorExample/Pods-ReactNativeRichTextEditorExample-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; - E37ABD7431ADE223A4A33FE5 /* [CP] Embed Pods Frameworks */ = { + 53EBC749589386D90FE2E60D /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -298,7 +281,7 @@ shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-ReactNativeRichTextEditorExample/Pods-ReactNativeRichTextEditorExample-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; - E8E8B1D71189538899D5EDEB /* [CP] Check Pods Manifest.lock */ = { + 69C011D95EDBCACAB3FC1113 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -320,6 +303,23 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; + B1576F9548D80B049BBF8E31 /* [CP] Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-ReactNativeRichTextEditorExample/Pods-ReactNativeRichTextEditorExample-resources-${CONFIGURATION}-input-files.xcfilelist", + ); + name = "[CP] Copy Pods Resources"; + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-ReactNativeRichTextEditorExample/Pods-ReactNativeRichTextEditorExample-resources-${CONFIGURATION}-output-files.xcfilelist", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-ReactNativeRichTextEditorExample/Pods-ReactNativeRichTextEditorExample-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -336,7 +336,7 @@ /* Begin XCBuildConfiguration section */ 13B07F941A680F5B00A75B9A /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = CE2992D25A1E9E45E24B984C /* Pods-ReactNativeRichTextEditorExample.debug.xcconfig */; + baseConfigurationReference = E6A46588CE906F8A9AC9DB45 /* Pods-ReactNativeRichTextEditorExample.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; @@ -364,7 +364,7 @@ }; 13B07F951A680F5B00A75B9A /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 30BAB32B24F7542D489838C7 /* Pods-ReactNativeRichTextEditorExample.release.xcconfig */; + baseConfigurationReference = 3C13A583FC86796D0F36DF7C /* Pods-ReactNativeRichTextEditorExample.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; diff --git a/ios/ReactNativeRichTextEditorView.h b/ios/EnrichedTextInputView.h similarity index 64% rename from ios/ReactNativeRichTextEditorView.h rename to ios/EnrichedTextInputView.h index 3e7fb107e..ec4670b7a 100644 --- a/ios/ReactNativeRichTextEditorView.h +++ b/ios/EnrichedTextInputView.h @@ -1,21 +1,21 @@ #pragma once #import #import -#import "EditorConfig.h" -#import "EditorParser.h" +#import "InputConfig.h" +#import "InputParser.h" #import "BaseStyleProtocol.h" -#import "EditorTextView.h" +#import "InputTextView.h" -#ifndef ReactNativeRichTextEditorViewNativeComponent_h -#define ReactNativeRichTextEditorViewNativeComponent_h +#ifndef EnrichedTextInputViewNativeComponent_h +#define EnrichedTextInputViewNativeComponent_h NS_ASSUME_NONNULL_BEGIN -@interface ReactNativeRichTextEditorView : RCTViewComponentView { - @public EditorTextView *textView; +@interface EnrichedTextInputView : RCTViewComponentView { + @public InputTextView *textView; @public NSRange recentlyChangedRange; - @public EditorConfig *config; - @public EditorParser *parser; + @public InputConfig *config; + @public InputParser *parser; @public NSMutableDictionary *defaultTypingAttributes; @public NSDictionary> *stylesDict; @public BOOL blockEmitting; @@ -30,4 +30,4 @@ NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_END -#endif /* ReactNativeRichTextEditorViewNativeComponent_h */ +#endif /* EnrichedTextInputViewNativeComponent_h */ diff --git a/ios/ReactNativeRichTextEditorView.mm b/ios/EnrichedTextInputView.mm similarity index 86% rename from ios/ReactNativeRichTextEditorView.mm rename to ios/EnrichedTextInputView.mm index ea21cf3f3..13f928bba 100644 --- a/ios/ReactNativeRichTextEditorView.mm +++ b/ios/EnrichedTextInputView.mm @@ -1,9 +1,9 @@ -#import "ReactNativeRichTextEditorView.h" +#import "EnrichedTextInputView.h" #import "RCTFabricComponentsPlugins.h" -#import -#import -#import -#import +#import +#import +#import +#import #import #import #import "UIView+React.h" @@ -17,12 +17,12 @@ using namespace facebook::react; -@interface ReactNativeRichTextEditorView () +@interface EnrichedTextInputView () @end -@implementation ReactNativeRichTextEditorView { - ReactNativeRichTextEditorViewShadowNode::ConcreteState::Shared _state; +@implementation EnrichedTextInputView { + EnrichedTextInputViewShadowNode::ConcreteState::Shared _state; int _componentViewHeightUpdateCounter; NSMutableSet *_activeStyles; NSDictionary *> *_conflictingStyles; @@ -41,11 +41,11 @@ @implementation ReactNativeRichTextEditorView { // MARK: - Component utils + (ComponentDescriptorProvider)componentDescriptorProvider { - return concreteComponentDescriptorProvider(); + return concreteComponentDescriptorProvider(); } -Class ReactNativeRichTextEditorViewCls(void) { - return ReactNativeRichTextEditorView.class; +Class EnrichedTextInputViewCls(void) { + return EnrichedTextInputView.class; } + (BOOL)shouldBeRecycled { @@ -56,7 +56,7 @@ + (BOOL)shouldBeRecycled { - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { - static const auto defaultProps = std::make_shared(); + static const auto defaultProps = std::make_shared(); _props = defaultProps; [self setDefaults]; [self setupTextView]; @@ -81,19 +81,19 @@ - (void)setDefaults { defaultTypingAttributes = [[NSMutableDictionary alloc] init]; stylesDict = @{ - @([BoldStyle getStyleType]) : [[BoldStyle alloc] initWithEditor:self], - @([ItalicStyle getStyleType]): [[ItalicStyle alloc] initWithEditor:self], - @([UnderlineStyle getStyleType]): [[UnderlineStyle alloc] initWithEditor:self], - @([StrikethroughStyle getStyleType]): [[StrikethroughStyle alloc] initWithEditor:self], - @([InlineCodeStyle getStyleType]): [[InlineCodeStyle alloc] initWithEditor:self], - @([LinkStyle getStyleType]): [[LinkStyle alloc] initWithEditor:self], - @([MentionStyle getStyleType]): [[MentionStyle alloc] initWithEditor:self], - @([H1Style getStyleType]): [[H1Style alloc] initWithEditor:self], - @([H2Style getStyleType]): [[H2Style alloc] initWithEditor:self], - @([H3Style getStyleType]): [[H3Style alloc] initWithEditor:self], - @([UnorderedListStyle getStyleType]): [[UnorderedListStyle alloc] initWithEditor:self], - @([OrderedListStyle getStyleType]): [[OrderedListStyle alloc] initWithEditor:self], - @([BlockQuoteStyle getStyleType]): [[BlockQuoteStyle alloc] initWithEditor:self] + @([BoldStyle getStyleType]) : [[BoldStyle alloc] initWithInput:self], + @([ItalicStyle getStyleType]): [[ItalicStyle alloc] initWithInput:self], + @([UnderlineStyle getStyleType]): [[UnderlineStyle alloc] initWithInput:self], + @([StrikethroughStyle getStyleType]): [[StrikethroughStyle alloc] initWithInput:self], + @([InlineCodeStyle getStyleType]): [[InlineCodeStyle alloc] initWithInput:self], + @([LinkStyle getStyleType]): [[LinkStyle alloc] initWithInput:self], + @([MentionStyle getStyleType]): [[MentionStyle alloc] initWithInput:self], + @([H1Style getStyleType]): [[H1Style alloc] initWithInput:self], + @([H2Style getStyleType]): [[H2Style alloc] initWithInput:self], + @([H3Style getStyleType]): [[H3Style alloc] initWithInput:self], + @([UnorderedListStyle getStyleType]): [[UnorderedListStyle alloc] initWithInput:self], + @([OrderedListStyle getStyleType]): [[OrderedListStyle alloc] initWithInput:self], + @([BlockQuoteStyle getStyleType]): [[BlockQuoteStyle alloc] initWithInput:self] }; _conflictingStyles = @{ @@ -128,17 +128,17 @@ - (void)setDefaults { @([BlockQuoteStyle getStyleType]): @[], }; - parser = [[EditorParser alloc] initWithEditor:self]; + parser = [[InputParser alloc] initWithInput:self]; } - (void)setupTextView { - textView = [[EditorTextView alloc] init]; + textView = [[InputTextView alloc] init]; textView.backgroundColor = UIColor.clearColor; textView.textContainerInset = UIEdgeInsetsMake(0, 0, 0, 0); textView.textContainer.lineFragmentPadding = 0; textView.delegate = self; - textView.editor = self; - textView.layoutManager.editor = self; + textView.input = self; + textView.layoutManager.input = self; } - (void)setupPlaceholderLabel { @@ -159,21 +159,21 @@ - (void)setupPlaceholderLabel { // MARK: - Props - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps { - const auto &oldViewProps = *std::static_pointer_cast(_props); - const auto &newViewProps = *std::static_pointer_cast(props); + const auto &oldViewProps = *std::static_pointer_cast(_props); + const auto &newViewProps = *std::static_pointer_cast(props); BOOL isFirstMount = NO; BOOL stylePropChanged = NO; // initial config if(config == nullptr) { isFirstMount = YES; - config = [[EditorConfig alloc] init]; + config = [[InputConfig alloc] init]; } // any style prop changes: // firstly we create the new config for the changes - EditorConfig *newConfig = [config copy]; + InputConfig *newConfig = [config copy]; if(newViewProps.color != oldViewProps.color) { if(isColorMeaningful(newViewProps.color)) { @@ -215,91 +215,91 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & // rich text style - if(newViewProps.richTextStyle.h1.fontSize != oldViewProps.richTextStyle.h1.fontSize) { - [newConfig setH1FontSize:newViewProps.richTextStyle.h1.fontSize]; + if(newViewProps.htmlStyle.h1.fontSize != oldViewProps.htmlStyle.h1.fontSize) { + [newConfig setH1FontSize:newViewProps.htmlStyle.h1.fontSize]; stylePropChanged = YES; } - if(newViewProps.richTextStyle.h1.bold != oldViewProps.richTextStyle.h1.bold) { - [newConfig setH1Bold:newViewProps.richTextStyle.h1.bold]; + if(newViewProps.htmlStyle.h1.bold != oldViewProps.htmlStyle.h1.bold) { + [newConfig setH1Bold:newViewProps.htmlStyle.h1.bold]; stylePropChanged = YES; } - if(newViewProps.richTextStyle.h2.fontSize != oldViewProps.richTextStyle.h2.fontSize) { - [newConfig setH2FontSize:newViewProps.richTextStyle.h2.fontSize]; + if(newViewProps.htmlStyle.h2.fontSize != oldViewProps.htmlStyle.h2.fontSize) { + [newConfig setH2FontSize:newViewProps.htmlStyle.h2.fontSize]; stylePropChanged = YES; } - if(newViewProps.richTextStyle.h2.bold != oldViewProps.richTextStyle.h2.bold) { - [newConfig setH2Bold:newViewProps.richTextStyle.h2.bold]; + if(newViewProps.htmlStyle.h2.bold != oldViewProps.htmlStyle.h2.bold) { + [newConfig setH2Bold:newViewProps.htmlStyle.h2.bold]; stylePropChanged = YES; } - if(newViewProps.richTextStyle.h3.fontSize != oldViewProps.richTextStyle.h3.fontSize) { - [newConfig setH3FontSize:newViewProps.richTextStyle.h3.fontSize]; + if(newViewProps.htmlStyle.h3.fontSize != oldViewProps.htmlStyle.h3.fontSize) { + [newConfig setH3FontSize:newViewProps.htmlStyle.h3.fontSize]; stylePropChanged = YES; } - if(newViewProps.richTextStyle.h3.bold != oldViewProps.richTextStyle.h3.bold) { - [newConfig setH3Bold:newViewProps.richTextStyle.h3.bold]; + if(newViewProps.htmlStyle.h3.bold != oldViewProps.htmlStyle.h3.bold) { + [newConfig setH3Bold:newViewProps.htmlStyle.h3.bold]; stylePropChanged = YES; } - if(newViewProps.richTextStyle.blockquote.borderColor != oldViewProps.richTextStyle.blockquote.borderColor) { - if(isColorMeaningful(newViewProps.richTextStyle.blockquote.borderColor)) { - [newConfig setBlockquoteBorderColor:RCTUIColorFromSharedColor(newViewProps.richTextStyle.blockquote.borderColor)]; + if(newViewProps.htmlStyle.blockquote.borderColor != oldViewProps.htmlStyle.blockquote.borderColor) { + if(isColorMeaningful(newViewProps.htmlStyle.blockquote.borderColor)) { + [newConfig setBlockquoteBorderColor:RCTUIColorFromSharedColor(newViewProps.htmlStyle.blockquote.borderColor)]; stylePropChanged = YES; } } - if(newViewProps.richTextStyle.blockquote.borderWidth != oldViewProps.richTextStyle.blockquote.borderWidth) { - [newConfig setBlockquoteBorderWidth:newViewProps.richTextStyle.blockquote.borderWidth]; + if(newViewProps.htmlStyle.blockquote.borderWidth != oldViewProps.htmlStyle.blockquote.borderWidth) { + [newConfig setBlockquoteBorderWidth:newViewProps.htmlStyle.blockquote.borderWidth]; stylePropChanged = YES; } - if(newViewProps.richTextStyle.blockquote.gapWidth != oldViewProps.richTextStyle.blockquote.gapWidth) { - [newConfig setBlockquoteGapWidth:newViewProps.richTextStyle.blockquote.gapWidth]; + if(newViewProps.htmlStyle.blockquote.gapWidth != oldViewProps.htmlStyle.blockquote.gapWidth) { + [newConfig setBlockquoteGapWidth:newViewProps.htmlStyle.blockquote.gapWidth]; stylePropChanged = YES; } // since this prop defaults to undefined on JS side, we need to force set the value on first mount - if(newViewProps.richTextStyle.blockquote.color != oldViewProps.richTextStyle.blockquote.color || isFirstMount) { - if(isColorMeaningful(newViewProps.richTextStyle.blockquote.color)) { - [newConfig setBlockquoteColor:RCTUIColorFromSharedColor(newViewProps.richTextStyle.blockquote.color)]; + if(newViewProps.htmlStyle.blockquote.color != oldViewProps.htmlStyle.blockquote.color || isFirstMount) { + if(isColorMeaningful(newViewProps.htmlStyle.blockquote.color)) { + [newConfig setBlockquoteColor:RCTUIColorFromSharedColor(newViewProps.htmlStyle.blockquote.color)]; } else { [newConfig setBlockquoteColor:[newConfig primaryColor]]; } stylePropChanged = YES; } - if(newViewProps.richTextStyle.code.color != oldViewProps.richTextStyle.code.color) { - if(isColorMeaningful(newViewProps.richTextStyle.code.color)) { - [newConfig setInlineCodeFgColor:RCTUIColorFromSharedColor(newViewProps.richTextStyle.code.color)]; + if(newViewProps.htmlStyle.code.color != oldViewProps.htmlStyle.code.color) { + if(isColorMeaningful(newViewProps.htmlStyle.code.color)) { + [newConfig setInlineCodeFgColor:RCTUIColorFromSharedColor(newViewProps.htmlStyle.code.color)]; stylePropChanged = YES; } } - if(newViewProps.richTextStyle.code.backgroundColor != oldViewProps.richTextStyle.code.backgroundColor) { - if(isColorMeaningful(newViewProps.richTextStyle.code.backgroundColor)) { - [newConfig setInlineCodeBgColor:RCTUIColorFromSharedColor(newViewProps.richTextStyle.code.backgroundColor)]; + if(newViewProps.htmlStyle.code.backgroundColor != oldViewProps.htmlStyle.code.backgroundColor) { + if(isColorMeaningful(newViewProps.htmlStyle.code.backgroundColor)) { + [newConfig setInlineCodeBgColor:RCTUIColorFromSharedColor(newViewProps.htmlStyle.code.backgroundColor)]; stylePropChanged = YES; } } - if(newViewProps.richTextStyle.ol.gapWidth != oldViewProps.richTextStyle.ol.gapWidth) { - [newConfig setOrderedListGapWidth:newViewProps.richTextStyle.ol.gapWidth]; + if(newViewProps.htmlStyle.ol.gapWidth != oldViewProps.htmlStyle.ol.gapWidth) { + [newConfig setOrderedListGapWidth:newViewProps.htmlStyle.ol.gapWidth]; stylePropChanged = YES; } - if(newViewProps.richTextStyle.ol.marginLeft != oldViewProps.richTextStyle.ol.marginLeft) { - [newConfig setOrderedListMarginLeft:newViewProps.richTextStyle.ol.marginLeft]; + if(newViewProps.htmlStyle.ol.marginLeft != oldViewProps.htmlStyle.ol.marginLeft) { + [newConfig setOrderedListMarginLeft:newViewProps.htmlStyle.ol.marginLeft]; stylePropChanged = YES; } // since this prop defaults to undefined on JS side, we need to force set the value on first mount - if(newViewProps.richTextStyle.ol.markerFontWeight != oldViewProps.richTextStyle.ol.markerFontWeight || isFirstMount) { - if(!newViewProps.richTextStyle.ol.markerFontWeight.empty()) { - [newConfig setOrderedListMarkerFontWeight:[NSString fromCppString: newViewProps.richTextStyle.ol.markerFontWeight]]; + if(newViewProps.htmlStyle.ol.markerFontWeight != oldViewProps.htmlStyle.ol.markerFontWeight || isFirstMount) { + if(!newViewProps.htmlStyle.ol.markerFontWeight.empty()) { + [newConfig setOrderedListMarkerFontWeight:[NSString fromCppString: newViewProps.htmlStyle.ol.markerFontWeight]]; } else { [newConfig setOrderedListMarkerFontWeight:[newConfig primaryFontWeight]]; } @@ -307,46 +307,46 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & } // since this prop defaults to undefined on JS side, we need to force set the value on first mount - if(newViewProps.richTextStyle.ol.markerColor != oldViewProps.richTextStyle.ol.markerColor || isFirstMount) { - if(isColorMeaningful(newViewProps.richTextStyle.ol.markerColor)) { - [newConfig setOrderedListMarkerColor:RCTUIColorFromSharedColor(newViewProps.richTextStyle.ol.markerColor)]; + if(newViewProps.htmlStyle.ol.markerColor != oldViewProps.htmlStyle.ol.markerColor || isFirstMount) { + if(isColorMeaningful(newViewProps.htmlStyle.ol.markerColor)) { + [newConfig setOrderedListMarkerColor:RCTUIColorFromSharedColor(newViewProps.htmlStyle.ol.markerColor)]; } else { [newConfig setOrderedListMarkerColor:[newConfig primaryColor]]; } stylePropChanged = YES; } - if(newViewProps.richTextStyle.ul.bulletColor != oldViewProps.richTextStyle.ul.bulletColor) { - if(isColorMeaningful(newViewProps.richTextStyle.ul.bulletColor)) { - [newConfig setUnorderedListBulletColor:RCTUIColorFromSharedColor(newViewProps.richTextStyle.ul.bulletColor)]; + if(newViewProps.htmlStyle.ul.bulletColor != oldViewProps.htmlStyle.ul.bulletColor) { + if(isColorMeaningful(newViewProps.htmlStyle.ul.bulletColor)) { + [newConfig setUnorderedListBulletColor:RCTUIColorFromSharedColor(newViewProps.htmlStyle.ul.bulletColor)]; stylePropChanged = YES; } } - if(newViewProps.richTextStyle.ul.bulletSize != oldViewProps.richTextStyle.ul.bulletSize) { - [newConfig setUnorderedListBulletSize:newViewProps.richTextStyle.ul.bulletSize]; + if(newViewProps.htmlStyle.ul.bulletSize != oldViewProps.htmlStyle.ul.bulletSize) { + [newConfig setUnorderedListBulletSize:newViewProps.htmlStyle.ul.bulletSize]; stylePropChanged = YES; } - if(newViewProps.richTextStyle.ul.gapWidth != oldViewProps.richTextStyle.ul.gapWidth) { - [newConfig setUnorderedListGapWidth:newViewProps.richTextStyle.ul.gapWidth]; + if(newViewProps.htmlStyle.ul.gapWidth != oldViewProps.htmlStyle.ul.gapWidth) { + [newConfig setUnorderedListGapWidth:newViewProps.htmlStyle.ul.gapWidth]; stylePropChanged = YES; } - if(newViewProps.richTextStyle.ul.marginLeft != oldViewProps.richTextStyle.ul.marginLeft) { - [newConfig setUnorderedListMarginLeft:newViewProps.richTextStyle.ul.marginLeft]; + if(newViewProps.htmlStyle.ul.marginLeft != oldViewProps.htmlStyle.ul.marginLeft) { + [newConfig setUnorderedListMarginLeft:newViewProps.htmlStyle.ul.marginLeft]; stylePropChanged = YES; } - if(newViewProps.richTextStyle.a.color != oldViewProps.richTextStyle.a.color) { - if(isColorMeaningful(newViewProps.richTextStyle.a.color)) { - [newConfig setLinkColor:RCTUIColorFromSharedColor(newViewProps.richTextStyle.a.color)]; + if(newViewProps.htmlStyle.a.color != oldViewProps.htmlStyle.a.color) { + if(isColorMeaningful(newViewProps.htmlStyle.a.color)) { + [newConfig setLinkColor:RCTUIColorFromSharedColor(newViewProps.htmlStyle.a.color)]; stylePropChanged = YES; } } - if(newViewProps.richTextStyle.a.textDecorationLine != oldViewProps.richTextStyle.a.textDecorationLine) { - NSString *objcString = [NSString fromCppString:newViewProps.richTextStyle.a.textDecorationLine]; + if(newViewProps.htmlStyle.a.textDecorationLine != oldViewProps.htmlStyle.a.textDecorationLine) { + NSString *objcString = [NSString fromCppString:newViewProps.htmlStyle.a.textDecorationLine]; if([objcString isEqualToString:DecorationUnderline]) { [newConfig setLinkDecorationLine:DecorationUnderline]; } else { @@ -356,8 +356,8 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & stylePropChanged = YES; } - folly::dynamic oldMentionStyle = oldViewProps.richTextStyle.mention; - folly::dynamic newMentionStyle = newViewProps.richTextStyle.mention; + folly::dynamic oldMentionStyle = oldViewProps.htmlStyle.mention; + folly::dynamic newMentionStyle = newViewProps.htmlStyle.mention; if(oldMentionStyle != newMentionStyle) { bool newSingleProps = NO; @@ -580,7 +580,7 @@ - (CGSize)measureSize:(CGFloat)maxWidth { // make sure the newest state is kept in _state property - (void)updateState:(State::Shared const &)state oldState:(State::Shared const &)oldState { - _state = std::static_pointer_cast(state); + _state = std::static_pointer_cast(state); // first render with all the needed stuff already defined (state and componentView) // so we need to run a single height calculation for any initial values @@ -595,7 +595,7 @@ - (void)tryUpdatingHeight { } _componentViewHeightUpdateCounter++; auto selfRef = wrapManagedObjectWeakly(self); - _state->updateState(ReactNativeRichTextEditorViewState(_componentViewHeightUpdateCounter, selfRef)); + _state->updateState(EnrichedTextInputViewState(_componentViewHeightUpdateCounter, selfRef)); } // MARK: - Active styles @@ -770,10 +770,10 @@ - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args { } } -- (std::shared_ptr)getEventEmitter { +- (std::shared_ptr)getEventEmitter { if(_eventEmitter != nullptr && !blockEmitting) { - auto emitter = static_cast(*_eventEmitter); - return std::make_shared(emitter); + auto emitter = static_cast(*_eventEmitter); + return std::make_shared(emitter); } else { return nullptr; } @@ -1002,7 +1002,7 @@ - (void)anyTextMayHaveBeenModified { } // zero width space removal - [ZeroWidthSpaceUtils handleZeroWidthSpacesInEditor:self]; + [ZeroWidthSpaceUtils handleZeroWidthSpacesInInput:self]; // inline code on newlines fix InlineCodeStyle *codeStyle = stylesDict[@([InlineCodeStyle getStyleType])]; @@ -1150,7 +1150,7 @@ - (bool)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range r } // zero width space removal fix - rejectTextChanges = rejectTextChanges || [ZeroWidthSpaceUtils handleBackspaceInRange:range replacementText:text editor:self]; + rejectTextChanges = rejectTextChanges || [ZeroWidthSpaceUtils handleBackspaceInRange:range replacementText:text input:self]; if(rejectTextChanges) { [self anyTextMayHaveBeenModified]; diff --git a/ios/EnrichedTextInputViewManager.mm b/ios/EnrichedTextInputViewManager.mm new file mode 100644 index 000000000..53d913eb7 --- /dev/null +++ b/ios/EnrichedTextInputViewManager.mm @@ -0,0 +1,13 @@ +#import +#import + +@interface EnrichedTextInputViewManager : RCTViewManager +@end + +@implementation EnrichedTextInputViewManager + +RCT_EXPORT_MODULE(EnrichedTextInputView) + +RCT_EXPORT_VIEW_PROPERTY(defaultValue, NSString) + +@end diff --git a/ios/ReactNativeRichTextEditorViewManager.mm b/ios/ReactNativeRichTextEditorViewManager.mm deleted file mode 100644 index e1c1f9e1e..000000000 --- a/ios/ReactNativeRichTextEditorViewManager.mm +++ /dev/null @@ -1,13 +0,0 @@ -#import -#import - -@interface ReactNativeRichTextEditorViewManager : RCTViewManager -@end - -@implementation ReactNativeRichTextEditorViewManager - -RCT_EXPORT_MODULE(ReactNativeRichTextEditorView) - -RCT_EXPORT_VIEW_PROPERTY(defaultValue, NSString) - -@end diff --git a/ios/config/EditorConfig.h b/ios/config/InputConfig.h similarity index 98% rename from ios/config/EditorConfig.h rename to ios/config/InputConfig.h index 86a7f33ac..cd12910c6 100644 --- a/ios/config/EditorConfig.h +++ b/ios/config/InputConfig.h @@ -3,7 +3,7 @@ #import "TextDecorationLineEnum.h" #import "MentionStyleProps.h" -@interface EditorConfig: NSObject +@interface InputConfig: NSObject - (instancetype) init; - (UIColor *)primaryColor; - (void)setPrimaryColor:(UIColor *)newValue; diff --git a/ios/config/EditorConfig.mm b/ios/config/InputConfig.mm similarity index 98% rename from ios/config/EditorConfig.mm rename to ios/config/InputConfig.mm index 82c85793f..00f0903c1 100644 --- a/ios/config/EditorConfig.mm +++ b/ios/config/InputConfig.mm @@ -1,7 +1,7 @@ -#import +#import #import -@implementation EditorConfig { +@implementation InputConfig { UIColor *_primaryColor; NSNumber *_primaryFontSize; NSString *_primaryFontWeight; @@ -47,7 +47,7 @@ - (instancetype) init { } - (id)copyWithZone:(NSZone *)zone { - EditorConfig *copy = [[[self class] allocWithZone:zone] init]; + InputConfig *copy = [[[self class] allocWithZone:zone] init]; copy->_primaryColor = [_primaryColor copy]; copy->_primaryFontSize = [_primaryFontSize copy]; copy->_primaryFontWeight = [_primaryFontWeight copy]; diff --git a/ios/editorTextView/EditorTextView.h b/ios/editorTextView/EditorTextView.h deleted file mode 100644 index d51371643..000000000 --- a/ios/editorTextView/EditorTextView.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once -#import - -@interface EditorTextView : UITextView -@property (nonatomic, weak) id editor; -@end diff --git a/ios/parser/EditorParser.h b/ios/inputParser/InputParser.h similarity index 79% rename from ios/parser/EditorParser.h rename to ios/inputParser/InputParser.h index c0d107c32..5c3583298 100644 --- a/ios/parser/EditorParser.h +++ b/ios/inputParser/InputParser.h @@ -1,8 +1,8 @@ #pragma once #import -@interface EditorParser : NSObject -- (instancetype _Nonnull)initWithEditor:(id _Nonnull)editor; +@interface InputParser : NSObject +- (instancetype _Nonnull)initWithInput:(id _Nonnull)input; - (NSString * _Nonnull)parseToHtmlFromRange:(NSRange)range; - (void)replaceWholeFromHtml:(NSString * _Nonnull)html; - (void)replaceFromHtml:(NSString * _Nonnull)html range:(NSRange)range; diff --git a/ios/parser/EditorParser.mm b/ios/inputParser/InputParser.mm similarity index 94% rename from ios/parser/EditorParser.mm rename to ios/inputParser/InputParser.mm index 348df4c5b..c671f48e3 100644 --- a/ios/parser/EditorParser.mm +++ b/ios/inputParser/InputParser.mm @@ -1,22 +1,22 @@ -#import "EditorParser.h" -#import "ReactNativeRichTextEditorView.h" +#import "InputParser.h" +#import "EnrichedTextInputView.h" #import "StyleHeaders.h" #import "UIView+React.h" #import "TextInsertionUtils.h" -@implementation EditorParser { - ReactNativeRichTextEditorView *_editor; +@implementation InputParser { + EnrichedTextInputView *_input; } -- (instancetype)initWithEditor:(id)editor { +- (instancetype)initWithInput:(id)input { self = [super init]; - _editor = (ReactNativeRichTextEditorView *) editor; + _input = (EnrichedTextInputView *)input; return self; } - (NSString *)parseToHtmlFromRange:(NSRange)range { NSInteger offset = range.location; - NSString *text = [_editor->textView.textStorage.string substringWithRange:range]; + NSString *text = [_input->textView.textStorage.string substringWithRange:range]; if(text.length == 0) { return @"\n

\n"; @@ -36,8 +36,8 @@ - (NSString *)parseToHtmlFromRange:(NSRange)range { NSMutableDictionary *currentActiveStylesBeginning = [[NSMutableDictionary alloc] init]; // check each existing style existence - for(NSNumber* type in _editor->stylesDict) { - id style = _editor->stylesDict[type]; + for(NSNumber* type in _input->stylesDict) { + id style = _input->stylesDict[type]; if([style detectStyle:currentRange]) { [currentActiveStyles addObject:type]; @@ -49,15 +49,15 @@ - (NSString *)parseToHtmlFromRange:(NSRange)range { } } - NSString *currentCharacterStr = [_editor->textView.textStorage.string substringWithRange:currentRange]; - unichar currentCharacterChar = [_editor->textView.textStorage.string characterAtIndex:currentRange.location]; + NSString *currentCharacterStr = [_input->textView.textStorage.string substringWithRange:currentRange]; + unichar currentCharacterChar = [_input->textView.textStorage.string characterAtIndex:currentRange.location]; if([[NSCharacterSet newlineCharacterSet] characterIsMember:currentCharacterChar]) { if(newLine) { // we can either have an empty list item OR need to close the list and put a BR in such a situation // the existence of the list must be checked on 0 length range, not on the newline character if(inOrderedList) { - OrderedListStyle *oStyle = _editor->stylesDict[@(OrderedList)]; + OrderedListStyle *oStyle = _input->stylesDict[@(OrderedList)]; BOOL detected = [oStyle detectStyle: NSMakeRange(currentRange.location, 0)]; if(detected) { [result appendString:@"\n
  • "]; @@ -66,7 +66,7 @@ - (NSString *)parseToHtmlFromRange:(NSRange)range { inOrderedList = NO; } } else if(inUnorderedList) { - UnorderedListStyle *uStyle = _editor->stylesDict[@(UnorderedList)]; + UnorderedListStyle *uStyle = _input->stylesDict[@(UnorderedList)]; BOOL detected = [uStyle detectStyle: NSMakeRange(currentRange.location, 0)]; if(detected) { [result appendString:@"\n
  • "]; @@ -221,7 +221,7 @@ - (NSString *)parseToHtmlFromRange:(NSRange)range { // append closing tags for(NSNumber *style in sortedEndedStyles) { - NSString *tagContent = [self tagContentForStyle:style openingTag:NO location:_editor->textView.textStorage.string.length - 1]; + NSString *tagContent = [self tagContentForStyle:style openingTag:NO location:_input->textView.textStorage.string.length - 1]; [result appendString: [NSString stringWithFormat:@"", tagContent]]; } @@ -279,7 +279,7 @@ - (NSString *)tagContentForStyle:(NSNumber *)style openingTag:(BOOL)openingTag l return @"code"; } else if([style isEqualToNumber: @([LinkStyle getStyleType])]) { if(openingTag) { - LinkStyle *linkStyle = (LinkStyle *)_editor->stylesDict[@([LinkStyle getStyleType])]; + LinkStyle *linkStyle = (LinkStyle *)_input->stylesDict[@([LinkStyle getStyleType])]; if(linkStyle != nullptr) { LinkData *data = [linkStyle getLinkDataAt: location]; if(data != nullptr && data.url != nullptr) { @@ -292,7 +292,7 @@ - (NSString *)tagContentForStyle:(NSNumber *)style openingTag:(BOOL)openingTag l } } else if([style isEqualToNumber: @([MentionStyle getStyleType])]) { if(openingTag) { - MentionStyle *mentionStyle = (MentionStyle *)_editor->stylesDict[@([MentionStyle getStyleType])]; + MentionStyle *mentionStyle = (MentionStyle *)_input->stylesDict[@([MentionStyle getStyleType])]; if(mentionStyle != nullptr) { MentionParams *params = [mentionStyle getMentionParamsAt:location]; // attributes can theoretically be nullptr @@ -339,11 +339,11 @@ - (void)replaceWholeFromHtml:(NSString * _Nonnull)html { NSArray *stylesInfo = (NSArray *)processingResult[1]; // reset the text first and reset typing attributes - _editor->textView.text = @""; - _editor->textView.typingAttributes = _editor->defaultTypingAttributes; + _input->textView.text = @""; + _input->textView.typingAttributes = _input->defaultTypingAttributes; // set new text - _editor->textView.text = plainText; + _input->textView.text = plainText; // re-apply the styles [self applyProcessedStyles:stylesInfo offsetFromBeginning:0]; @@ -355,7 +355,7 @@ - (void)replaceFromHtml:(NSString * _Nonnull)html range:(NSRange)range { NSArray *stylesInfo = (NSArray *)processingResult[1]; // we can use ready replace util - [TextInsertionUtils replaceText:plainText at:range additionalAttributes:nil editor:_editor withSelection:YES]; + [TextInsertionUtils replaceText:plainText at:range additionalAttributes:nil input:_input withSelection:YES]; [self applyProcessedStyles:stylesInfo offsetFromBeginning:range.location]; } @@ -366,7 +366,7 @@ - (void)insertFromHtml:(NSString * _Nonnull)html location:(NSInteger)location { NSArray *stylesInfo = (NSArray *)processingResult[1]; // same here, insertion utils got our back - [TextInsertionUtils insertText:plainText at:location additionalAttributes:nil editor:_editor withSelection:YES]; + [TextInsertionUtils insertText:plainText at:location additionalAttributes:nil input:_input withSelection:YES]; [self applyProcessedStyles:stylesInfo offsetFromBeginning:location]; } @@ -376,15 +376,15 @@ - (void)applyProcessedStyles:(NSArray *)processedStyles offsetFromBeginning:(NSI // unwrap all info from processed style NSNumber *styleType = (NSNumber *)arr[0]; StylePair *stylePair = (StylePair *)arr[1]; - id baseStyle = _editor->stylesDict[styleType]; + id baseStyle = _input->stylesDict[styleType]; // range must be taking offest into consideration because processed styles' ranges are relative to only the new text // while we need absolute ranges relative to the whole existing text NSRange styleRange = NSMakeRange(offset + [stylePair.rangeValue rangeValue].location, [stylePair.rangeValue rangeValue].length); // of course any changes here need to take blocks and conflicts into consideration - if([_editor handleStyleBlocksAndConflicts:[[baseStyle class] getStyleType] range:styleRange]) { + if([_input handleStyleBlocksAndConflicts:[[baseStyle class] getStyleType] range:styleRange]) { if([styleType isEqualToNumber: @([LinkStyle getStyleType])]) { - NSString *text = [_editor->textView.textStorage.string substringWithRange:styleRange]; + NSString *text = [_input->textView.textStorage.string substringWithRange:styleRange]; NSString *url = (NSString *)stylePair.styleValue; BOOL isManual = ![text isEqualToString:url]; [((LinkStyle *)baseStyle) addLink:text url:url range:styleRange manual:isManual]; @@ -396,7 +396,7 @@ - (void)applyProcessedStyles:(NSArray *)processedStyles offsetFromBeginning:(NSI } } } - [_editor anyTextMayHaveBeenModified]; + [_input anyTextMayHaveBeenModified]; } - (NSString * _Nullable)initiallyProcessHtml:(NSString * _Nonnull)html { diff --git a/ios/inputTextView/InputTextView.h b/ios/inputTextView/InputTextView.h new file mode 100644 index 000000000..f11659370 --- /dev/null +++ b/ios/inputTextView/InputTextView.h @@ -0,0 +1,6 @@ +#pragma once +#import + +@interface InputTextView : UITextView +@property (nonatomic, weak) id input; +@end diff --git a/ios/editorTextView/EditorTextView.mm b/ios/inputTextView/InputTextView.mm similarity index 62% rename from ios/editorTextView/EditorTextView.mm rename to ios/inputTextView/InputTextView.mm index 56f4543ea..29c832357 100644 --- a/ios/editorTextView/EditorTextView.mm +++ b/ios/inputTextView/InputTextView.mm @@ -1,22 +1,22 @@ -#import "EditorTextView.h" -#import "ReactNativeRichTextEditorView.h" +#import "InputTextView.h" +#import "EnrichedTextInputView.h" #import "StringExtension.h" #import #import "TextInsertionUtils.h" -@implementation EditorTextView +@implementation InputTextView - (void)copy:(id)sender { - ReactNativeRichTextEditorView *typedEditor = (ReactNativeRichTextEditorView *)_editor; - if(typedEditor == nullptr) { return; } + EnrichedTextInputView *typedInput = (EnrichedTextInputView *)_input; + if(typedInput == nullptr) { return; } // remove zero width spaces before copying the text - NSString *plainText = [typedEditor->textView.textStorage.string substringWithRange:typedEditor->textView.selectedRange]; + NSString *plainText = [typedInput->textView.textStorage.string substringWithRange:typedInput->textView.selectedRange]; NSString *fixedPlainText = [plainText stringByReplacingOccurrencesOfString:@"\u200B" withString:@""]; - NSString *escapedHtml = [NSString stringByEscapingHtml:[typedEditor->parser parseToHtmlFromRange:typedEditor->textView.selectedRange]]; + NSString *escapedHtml = [NSString stringByEscapingHtml:[typedInput->parser parseToHtmlFromRange:typedInput->textView.selectedRange]]; - NSMutableAttributedString *attrStr = [[typedEditor->textView.textStorage attributedSubstringFromRange:typedEditor->textView.selectedRange] mutableCopy]; + NSMutableAttributedString *attrStr = [[typedInput->textView.textStorage attributedSubstringFromRange:typedInput->textView.selectedRange] mutableCopy]; NSRange fullAttrStrRange = NSMakeRange(0, attrStr.length); [attrStr.mutableString replaceOccurrencesOfString:@"\u200B" withString:@"" options:0 range:fullAttrStrRange]; @@ -34,12 +34,12 @@ - (void)copy:(id)sender { } - (void)paste:(id)sender { - ReactNativeRichTextEditorView *typedEditor = (ReactNativeRichTextEditorView *)_editor; - if(typedEditor == nullptr) { return; } + EnrichedTextInputView *typedInput = (EnrichedTextInputView *)_input; + if(typedInput == nullptr) { return; } UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; NSArray *pasteboardTypes = pasteboard.pasteboardTypes; - NSRange currentRange = typedEditor->textView.selectedRange; + NSRange currentRange = typedInput->textView.selectedRange; if([pasteboardTypes containsObject:UTTypeHTML.identifier]) { // we try processing the html contents @@ -56,25 +56,25 @@ - (void)paste:(id)sender { // unescape the html htmlString = [NSString stringByUnescapingHtml:htmlString]; // validate it - NSString *initiallyProcessedHtml = [typedEditor->parser initiallyProcessHtml:htmlString]; + NSString *initiallyProcessedHtml = [typedInput->parser initiallyProcessHtml:htmlString]; if(initiallyProcessedHtml != nullptr) { // valid html, let's apply it currentRange.length > 0 - ? [typedEditor->parser replaceFromHtml:initiallyProcessedHtml range:currentRange] - : [typedEditor->parser insertFromHtml:initiallyProcessedHtml location:currentRange.location]; + ? [typedInput->parser replaceFromHtml:initiallyProcessedHtml range:currentRange] + : [typedInput->parser insertFromHtml:initiallyProcessedHtml location:currentRange.location]; } else { // fall back to plain text, otherwise do nothing - [self tryHandlingPlainTextItemsIn:pasteboard range:currentRange editor:typedEditor]; + [self tryHandlingPlainTextItemsIn:pasteboard range:currentRange input:typedInput]; } } else { - [self tryHandlingPlainTextItemsIn:pasteboard range:currentRange editor:typedEditor]; + [self tryHandlingPlainTextItemsIn:pasteboard range:currentRange input:typedInput]; } - [typedEditor anyTextMayHaveBeenModified]; + [typedInput anyTextMayHaveBeenModified]; } -- (void)tryHandlingPlainTextItemsIn:(UIPasteboard *)pasteboard range:(NSRange)range editor:(ReactNativeRichTextEditorView *)editor { +- (void)tryHandlingPlainTextItemsIn:(UIPasteboard *)pasteboard range:(NSRange)range input:(EnrichedTextInputView *)input { NSArray *existingTypes = pasteboard.pasteboardTypes; NSArray *handledTypes = @[UTTypeUTF8PlainText.identifier, UTTypePlainText.identifier]; NSString *plainText; @@ -98,18 +98,18 @@ - (void)tryHandlingPlainTextItemsIn:(UIPasteboard *)pasteboard range:(NSRange)ra } range.length > 0 - ? [TextInsertionUtils replaceText:plainText at:range additionalAttributes:nullptr editor:editor withSelection:YES] - : [TextInsertionUtils insertText:plainText at:range.location additionalAttributes:nullptr editor:editor withSelection:YES]; + ? [TextInsertionUtils replaceText:plainText at:range additionalAttributes:nullptr input:input withSelection:YES] + : [TextInsertionUtils insertText:plainText at:range.location additionalAttributes:nullptr input:input withSelection:YES]; } - (void)cut:(id)sender { - ReactNativeRichTextEditorView *typedEditor = (ReactNativeRichTextEditorView *)_editor; - if(typedEditor == nullptr) { return; } + EnrichedTextInputView *typedInput = (EnrichedTextInputView *)_input; + if(typedInput == nullptr) { return; } [self copy:sender]; - [TextInsertionUtils replaceText:@"" at:typedEditor->textView.selectedRange additionalAttributes:nullptr editor:typedEditor withSelection:YES]; + [TextInsertionUtils replaceText:@"" at:typedInput->textView.selectedRange additionalAttributes:nullptr input:typedInput withSelection:YES]; - [typedEditor anyTextMayHaveBeenModified]; + [typedInput anyTextMayHaveBeenModified]; } @end diff --git a/ios/internals/ReactNativeRichTextEditorViewComponentDescriptor.h b/ios/internals/EnrichedTextInputViewComponentDescriptor.h similarity index 51% rename from ios/internals/ReactNativeRichTextEditorViewComponentDescriptor.h rename to ios/internals/EnrichedTextInputViewComponentDescriptor.h index 1433a2b85..ddffc4204 100644 --- a/ios/internals/ReactNativeRichTextEditorViewComponentDescriptor.h +++ b/ios/internals/EnrichedTextInputViewComponentDescriptor.h @@ -1,15 +1,15 @@ #pragma once #include -#include +#include #include -#include +#include namespace facebook::react { -class ReactNativeRichTextEditorViewComponentDescriptor final : public ConcreteComponentDescriptor { +class EnrichedTextInputViewComponentDescriptor final : public ConcreteComponentDescriptor { public: using ConcreteComponentDescriptor::ConcreteComponentDescriptor; void adopt(ShadowNode &shadowNode) const override { - react_native_assert(dynamic_cast(&shadowNode)); + react_native_assert(dynamic_cast(&shadowNode)); ConcreteComponentDescriptor::adopt(shadowNode); } }; diff --git a/ios/internals/EnrichedTextInputViewShadowNode.h b/ios/internals/EnrichedTextInputViewShadowNode.h new file mode 100644 index 000000000..1e3c5ffba --- /dev/null +++ b/ios/internals/EnrichedTextInputViewShadowNode.h @@ -0,0 +1,40 @@ +#pragma once +#include +#include +#include +#include +#include +#include + +namespace facebook::react { + +JSI_EXPORT extern const char EnrichedTextInputViewComponentName[]; + +/* + * `ShadowNode` for component. + */ +class EnrichedTextInputViewShadowNode : public ConcreteViewShadowNode< + EnrichedTextInputViewComponentName, + EnrichedTextInputViewProps, + EnrichedTextInputViewEventEmitter, + EnrichedTextInputViewState> { + public: + using ConcreteViewShadowNode::ConcreteViewShadowNode; + EnrichedTextInputViewShadowNode(const ShadowNodeFragment& fragment, const ShadowNodeFamily::Shared& family, ShadowNodeTraits traits); + EnrichedTextInputViewShadowNode(const ShadowNode& sourceShadowNode, const ShadowNodeFragment& fragment); + void dirtyLayoutIfNeeded(); + Size measureContent(const LayoutContext& layoutContext, const LayoutConstraints& layoutConstraints) const override; + + + static ShadowNodeTraits BaseTraits() { + auto traits = ConcreteViewShadowNode::BaseTraits(); + traits.set(ShadowNodeTraits::Trait::LeafYogaNode); + traits.set(ShadowNodeTraits::Trait::MeasurableYogaNode); + return traits; + } + + private: + int localForceHeightRecalculationCounter_; +}; + +} // namespace facebook::react diff --git a/ios/internals/ReactNativeRichTextEditorViewShadowNode.mm b/ios/internals/EnrichedTextInputViewShadowNode.mm similarity index 77% rename from ios/internals/ReactNativeRichTextEditorViewShadowNode.mm rename to ios/internals/EnrichedTextInputViewShadowNode.mm index 11a52e6c3..983d9c8f2 100644 --- a/ios/internals/ReactNativeRichTextEditorViewShadowNode.mm +++ b/ios/internals/EnrichedTextInputViewShadowNode.mm @@ -1,5 +1,5 @@ -#import "ReactNativeRichTextEditorViewShadowNode.h" -#import +#import "EnrichedTextInputViewShadowNode.h" +#import #import #import #import @@ -7,9 +7,9 @@ namespace facebook::react { -extern const char ReactNativeRichTextEditorViewComponentName[] = "ReactNativeRichTextEditorView"; +extern const char EnrichedTextInputViewComponentName[] = "EnrichedTextInputView"; -ReactNativeRichTextEditorViewShadowNode::ReactNativeRichTextEditorViewShadowNode( +EnrichedTextInputViewShadowNode::EnrichedTextInputViewShadowNode( const ShadowNodeFragment& fragment, const ShadowNodeFamily::Shared& family, ShadowNodeTraits traits @@ -17,14 +17,14 @@ localForceHeightRecalculationCounter_ = 0; } -ReactNativeRichTextEditorViewShadowNode::ReactNativeRichTextEditorViewShadowNode( +EnrichedTextInputViewShadowNode::EnrichedTextInputViewShadowNode( const ShadowNode& sourceShadowNode, const ShadowNodeFragment& fragment ): ConcreteViewShadowNode(sourceShadowNode, fragment) { dirtyLayoutIfNeeded(); } -void ReactNativeRichTextEditorViewShadowNode::dirtyLayoutIfNeeded() { +void EnrichedTextInputViewShadowNode::dirtyLayoutIfNeeded() { const auto state = this->getStateData(); const int receivedCounter = state.getForceHeightRecalculationCounter(); @@ -34,14 +34,14 @@ } } -Size ReactNativeRichTextEditorViewShadowNode::measureContent(const LayoutContext& layoutContext, const LayoutConstraints& layoutConstraints) const { +Size EnrichedTextInputViewShadowNode::measureContent(const LayoutContext& layoutContext, const LayoutConstraints& layoutConstraints) const { const auto state = this->getStateData(); const auto componentRef = state.getComponentViewRef(); RCTInternalGenericWeakWrapper *weakWrapper = (RCTInternalGenericWeakWrapper *)unwrapManagedObject(componentRef); if(weakWrapper != nullptr) { id componentObject = weakWrapper.object; - ReactNativeRichTextEditorView *typedComponentObject = (ReactNativeRichTextEditorView *) componentObject; + EnrichedTextInputView *typedComponentObject = (EnrichedTextInputView *) componentObject; if(typedComponentObject != nullptr) { __block CGSize estimatedSize; @@ -63,7 +63,7 @@ // in a lot of cases it will be the desired height // in others, the jump on the second call will at least be smaller const auto props = this->getProps(); - const auto &typedProps = *std::static_pointer_cast(props); + const auto &typedProps = *std::static_pointer_cast(props); NSAttributedString *attrStr = [[NSAttributedString alloc] initWithString:@"I" attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:typedProps.fontSize]}]; CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attrStr); const CGSize &suggestedSize = CTFramesetterSuggestFrameSizeWithConstraints( diff --git a/ios/internals/EnrichedTextInputViewState.cpp b/ios/internals/EnrichedTextInputViewState.cpp new file mode 100644 index 000000000..6d0eea37f --- /dev/null +++ b/ios/internals/EnrichedTextInputViewState.cpp @@ -0,0 +1,10 @@ +#include "EnrichedTextInputViewState.h" + +namespace facebook::react { + int EnrichedTextInputViewState::getForceHeightRecalculationCounter() const { + return forceHeightRecalculationCounter_; + } + std::shared_ptr EnrichedTextInputViewState::getComponentViewRef() const { + return componentViewRef_; + } +} // namespace facebook::react diff --git a/ios/internals/ReactNativeRichTextEditorViewState.h b/ios/internals/EnrichedTextInputViewState.h similarity index 62% rename from ios/internals/ReactNativeRichTextEditorViewState.h rename to ios/internals/EnrichedTextInputViewState.h index 9ebddb014..4d5ac6ade 100644 --- a/ios/internals/ReactNativeRichTextEditorViewState.h +++ b/ios/internals/EnrichedTextInputViewState.h @@ -3,10 +3,10 @@ namespace facebook::react { -class ReactNativeRichTextEditorViewState { +class EnrichedTextInputViewState { public: - ReactNativeRichTextEditorViewState(): forceHeightRecalculationCounter_(0), componentViewRef_(nullptr) {} - ReactNativeRichTextEditorViewState(int counter, std::shared_ptr ref) { + EnrichedTextInputViewState(): forceHeightRecalculationCounter_(0), componentViewRef_(nullptr) {} + EnrichedTextInputViewState(int counter, std::shared_ptr ref) { forceHeightRecalculationCounter_ = counter; componentViewRef_ = ref; } diff --git a/ios/internals/ReactNativeRichTextEditorViewShadowNode.h b/ios/internals/ReactNativeRichTextEditorViewShadowNode.h deleted file mode 100644 index e3deb63f6..000000000 --- a/ios/internals/ReactNativeRichTextEditorViewShadowNode.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include - -namespace facebook::react { - -JSI_EXPORT extern const char ReactNativeRichTextEditorViewComponentName[]; - -/* - * `ShadowNode` for component. - */ -class ReactNativeRichTextEditorViewShadowNode : public ConcreteViewShadowNode< - ReactNativeRichTextEditorViewComponentName, - ReactNativeRichTextEditorViewProps, - ReactNativeRichTextEditorViewEventEmitter, - ReactNativeRichTextEditorViewState> { - public: - using ConcreteViewShadowNode::ConcreteViewShadowNode; - ReactNativeRichTextEditorViewShadowNode(const ShadowNodeFragment& fragment, const ShadowNodeFamily::Shared& family, ShadowNodeTraits traits); - ReactNativeRichTextEditorViewShadowNode(const ShadowNode& sourceShadowNode, const ShadowNodeFragment& fragment); - void dirtyLayoutIfNeeded(); - Size measureContent(const LayoutContext& layoutContext, const LayoutConstraints& layoutConstraints) const override; - - - static ShadowNodeTraits BaseTraits() { - auto traits = ConcreteViewShadowNode::BaseTraits(); - traits.set(ShadowNodeTraits::Trait::LeafYogaNode); - traits.set(ShadowNodeTraits::Trait::MeasurableYogaNode); - return traits; - } - - private: - int localForceHeightRecalculationCounter_; -}; - -} // namespace facebook::react diff --git a/ios/internals/ReactNativeRichTextEditorViewState.cpp b/ios/internals/ReactNativeRichTextEditorViewState.cpp deleted file mode 100644 index dbcd62f82..000000000 --- a/ios/internals/ReactNativeRichTextEditorViewState.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "ReactNativeRichTextEditorViewState.h" - -namespace facebook::react { - int ReactNativeRichTextEditorViewState::getForceHeightRecalculationCounter() const { - return forceHeightRecalculationCounter_; - } - std::shared_ptr ReactNativeRichTextEditorViewState::getComponentViewRef() const { - return componentViewRef_; - } -} // namespace facebook::react diff --git a/ios/styles/BlockQuoteStyle.mm b/ios/styles/BlockQuoteStyle.mm index 2d7c5380a..f2eb77601 100644 --- a/ios/styles/BlockQuoteStyle.mm +++ b/ios/styles/BlockQuoteStyle.mm @@ -1,25 +1,25 @@ #import "StyleHeaders.h" -#import "ReactNativeRichTextEditorView.h" +#import "EnrichedTextInputView.h" #import "OccurenceUtils.h" #import "ParagraphsUtils.h" #import "TextInsertionUtils.h" #import "ColorExtension.h" @implementation BlockQuoteStyle { - ReactNativeRichTextEditorView *_editor; + EnrichedTextInputView *_input; } + (StyleType)getStyleType { return BlockQuote; } -- (instancetype)initWithEditor:(id)editor { +- (instancetype)initWithInput:(id)input { self = [super init]; - _editor = (ReactNativeRichTextEditorView *) editor; + _input = (EnrichedTextInputView *)input; return self; } - (CGFloat)getHeadIndent { // rectangle width + gap - return [_editor->config blockquoteBorderWidth] + [_editor->config blockquoteGapWidth]; + return [_input->config blockquoteBorderWidth] + [_input->config blockquoteGapWidth]; } // the range will already be the full paragraph/s range @@ -33,13 +33,13 @@ - (void)applyStyle:(NSRange)range { } - (void)addAttributes:(NSRange)range { - NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:_editor->textView range:range]; + NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView range:range]; // if we fill empty lines with zero width spaces, we need to offset later ranges NSInteger offset = 0; - NSRange preModificationRange = _editor->textView.selectedRange; + NSRange preModificationRange = _input->textView.selectedRange; // to not emit any space filling selection/text changes - _editor->blockEmitting = YES; + _input->blockEmitting = YES; for(NSValue *value in paragraphs) { NSRange pRange = NSMakeRange([value rangeValue].location + offset, [value rangeValue].length); @@ -47,85 +47,85 @@ - (void)addAttributes:(NSRange)range { // length 0 with first line, length 1 and newline with some empty lines in the middle if(pRange.length == 0 || (pRange.length == 1 && - [[NSCharacterSet newlineCharacterSet] characterIsMember: [_editor->textView.textStorage.string characterAtIndex:pRange.location]]) + [[NSCharacterSet newlineCharacterSet] characterIsMember: [_input->textView.textStorage.string characterAtIndex:pRange.location]]) ) { - [TextInsertionUtils insertText:@"\u200B" at:pRange.location additionalAttributes:nullptr editor:_editor withSelection:NO]; + [TextInsertionUtils insertText:@"\u200B" at:pRange.location additionalAttributes:nullptr input:_input withSelection:NO]; pRange = NSMakeRange(pRange.location, pRange.length + 1); offset += 1; } - [_editor->textView.textStorage enumerateAttribute:NSParagraphStyleAttributeName inRange:pRange options:0 + [_input->textView.textStorage enumerateAttribute:NSParagraphStyleAttributeName inRange:pRange options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { NSMutableParagraphStyle *pStyle = [(NSParagraphStyle *)value mutableCopy]; pStyle.headIndent = [self getHeadIndent]; pStyle.firstLineHeadIndent = [self getHeadIndent]; - [_editor->textView.textStorage addAttribute:NSParagraphStyleAttributeName value:pStyle range:range]; + [_input->textView.textStorage addAttribute:NSParagraphStyleAttributeName value:pStyle range:range]; } ]; } // back to emitting - _editor->blockEmitting = NO; + _input->blockEmitting = NO; if(preModificationRange.length == 0) { // fix selection if only one line was possibly made a list and filled with a space - _editor->textView.selectedRange = preModificationRange; + _input->textView.selectedRange = preModificationRange; } else { // in other cases, fix the selection with newly made offsets - _editor->textView.selectedRange = NSMakeRange(preModificationRange.location, preModificationRange.length + offset); + _input->textView.selectedRange = NSMakeRange(preModificationRange.location, preModificationRange.length + offset); } // also add typing attributes - NSMutableDictionary *typingAttrs = [_editor->textView.typingAttributes mutableCopy]; + NSMutableDictionary *typingAttrs = [_input->textView.typingAttributes mutableCopy]; NSMutableParagraphStyle *pStyle = [typingAttrs[NSParagraphStyleAttributeName] mutableCopy]; pStyle.headIndent = [self getHeadIndent]; pStyle.firstLineHeadIndent = [self getHeadIndent]; typingAttrs[NSParagraphStyleAttributeName] = pStyle; - _editor->textView.typingAttributes = typingAttrs; + _input->textView.typingAttributes = typingAttrs; } // does pretty much the same as addAttributes - (void)addTypingAttributes { - [self addAttributes:_editor->textView.selectedRange]; + [self addAttributes:_input->textView.selectedRange]; } - (void)removeAttributes:(NSRange)range { - NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:_editor->textView range:range]; + NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView range:range]; for(NSValue *value in paragraphs) { NSRange pRange = [value rangeValue]; - [_editor->textView.textStorage enumerateAttribute:NSParagraphStyleAttributeName inRange:pRange options:0 + [_input->textView.textStorage enumerateAttribute:NSParagraphStyleAttributeName inRange:pRange options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { NSMutableParagraphStyle *pStyle = [(NSParagraphStyle *)value mutableCopy]; pStyle.headIndent = 0; pStyle.firstLineHeadIndent = 0; - [_editor->textView.textStorage addAttribute:NSParagraphStyleAttributeName value:pStyle range:range]; + [_input->textView.textStorage addAttribute:NSParagraphStyleAttributeName value:pStyle range:range]; } ]; } // also remove typing attributes - NSMutableDictionary *typingAttrs = [_editor->textView.typingAttributes mutableCopy]; + NSMutableDictionary *typingAttrs = [_input->textView.typingAttributes mutableCopy]; NSMutableParagraphStyle *pStyle = [typingAttrs[NSParagraphStyleAttributeName] mutableCopy]; pStyle.headIndent = 0; pStyle.firstLineHeadIndent = 0; typingAttrs[NSParagraphStyleAttributeName] = pStyle; - _editor->textView.typingAttributes = typingAttrs; + _input->textView.typingAttributes = typingAttrs; } // needed for the sake of style conflicts, needs to do exactly the same as removeAttribtues - (void)removeTypingAttributes { - [self removeAttributes:_editor->textView.selectedRange]; + [self removeAttributes:_input->textView.selectedRange]; } // removing first quote line by backspacing doesn't remove typing attributes because it doesn't run textViewDidChange // so we try guessing that a point should be deleted here - (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text { - if([self detectStyle:_editor->textView.selectedRange] && - NSEqualRanges(_editor->textView.selectedRange, NSMakeRange(0, 0)) && + if([self detectStyle:_input->textView.selectedRange] && + NSEqualRanges(_input->textView.selectedRange, NSMakeRange(0, 0)) && [text isEqualToString:@""] ) { - NSRange paragraphRange = [_editor->textView.textStorage.string paragraphRangeForRange:_editor->textView.selectedRange]; + NSRange paragraphRange = [_input->textView.textStorage.string paragraphRangeForRange:_input->textView.selectedRange]; [self removeAttributes:paragraphRange]; return YES; } @@ -139,25 +139,25 @@ - (BOOL)styleCondition:(id _Nullable)value :(NSRange)range { - (BOOL)detectStyle:(NSRange)range { if(range.length >= 1) { - return [OccurenceUtils detect:NSParagraphStyleAttributeName withEditor:_editor inRange:range + return [OccurenceUtils detect:NSParagraphStyleAttributeName withInput:_input inRange:range withCondition: ^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } ]; } else { NSInteger searchLocation = range.location; - if(searchLocation == _editor->textView.textStorage.length) { - NSParagraphStyle *pStyle = _editor->textView.typingAttributes[NSParagraphStyleAttributeName]; + if(searchLocation == _input->textView.textStorage.length) { + NSParagraphStyle *pStyle = _input->textView.typingAttributes[NSParagraphStyleAttributeName]; return [self styleCondition:pStyle :NSMakeRange(0, 0)]; } NSRange paragraphRange = NSMakeRange(0, 0); - NSRange editorRange = NSMakeRange(0, _editor->textView.textStorage.length); - NSParagraphStyle *paragraph = [_editor->textView.textStorage + NSRange inputRange = NSMakeRange(0, _input->textView.textStorage.length); + NSParagraphStyle *paragraph = [_input->textView.textStorage attribute:NSParagraphStyleAttributeName atIndex:searchLocation longestEffectiveRange: ¶graphRange - inRange:editorRange + inRange:inputRange ]; return [self styleCondition:paragraph :NSMakeRange(0, 0)]; @@ -165,7 +165,7 @@ - (BOOL)detectStyle:(NSRange)range { } - (BOOL)anyOccurence:(NSRange)range { - return [OccurenceUtils any:NSParagraphStyleAttributeName withEditor:_editor inRange:range + return [OccurenceUtils any:NSParagraphStyleAttributeName withInput:_input inRange:range withCondition:^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } @@ -173,7 +173,7 @@ - (BOOL)anyOccurence:(NSRange)range { } - (NSArray *_Nullable)findAllOccurences:(NSRange)range { - return [OccurenceUtils all:NSParagraphStyleAttributeName withEditor:_editor inRange:range + return [OccurenceUtils all:NSParagraphStyleAttributeName withInput:_input inRange:range withCondition:^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } @@ -182,9 +182,9 @@ - (BOOL)anyOccurence:(NSRange)range { // gets ranges that aren't link, mention or inline code - (NSArray *)getProperColorRangesIn:(NSRange)range { - LinkStyle *linkStyle = _editor->stylesDict[@([LinkStyle getStyleType])]; - MentionStyle *mentionStyle = _editor->stylesDict[@([MentionStyle getStyleType])]; - InlineCodeStyle *codeStyle = _editor->stylesDict[@([InlineCodeStyle getStyleType])]; + LinkStyle *linkStyle = _input->stylesDict[@([LinkStyle getStyleType])]; + MentionStyle *mentionStyle = _input->stylesDict[@([MentionStyle getStyleType])]; + InlineCodeStyle *codeStyle = _input->stylesDict[@([InlineCodeStyle getStyleType])]; NSMutableArray *newRanges = [[NSMutableArray alloc] init]; int lastRangeLocation = range.location; @@ -208,13 +208,13 @@ - (NSArray *)getProperColorRangesIn:(NSRange)range { // general checkup correcting blockquote color // since links, mentions and inline code affects coloring, the checkup gets done only outside of them - (void)manageBlockquoteColor { - if([[_editor->config blockquoteColor] isEqualToColor:[_editor->config primaryColor]]) { + if([[_input->config blockquoteColor] isEqualToColor:[_input->config primaryColor]]) { return; } - NSRange wholeRange = NSMakeRange(0, _editor->textView.textStorage.string.length); + NSRange wholeRange = NSMakeRange(0, _input->textView.textStorage.string.length); - NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:_editor->textView range:wholeRange]; + NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView range:wholeRange]; for(NSValue *pValue in paragraphs) { NSRange paragraphRange = [pValue rangeValue]; NSArray *properRanges = [self getProperColorRangesIn:paragraphRange]; @@ -223,21 +223,21 @@ - (void)manageBlockquoteColor { NSRange currRange = [value rangeValue]; BOOL selfDetected = [self detectStyle:currRange]; - [_editor->textView.textStorage enumerateAttribute:NSForegroundColorAttributeName inRange:currRange options:0 + [_input->textView.textStorage enumerateAttribute:NSForegroundColorAttributeName inRange:currRange options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { UIColor *newColor = nullptr; - BOOL colorApplied = [(UIColor *)value isEqualToColor:[_editor->config blockquoteColor]]; + BOOL colorApplied = [(UIColor *)value isEqualToColor:[_input->config blockquoteColor]]; if(colorApplied && !selfDetected) { - newColor = [_editor->config primaryColor]; + newColor = [_input->config primaryColor]; } else if(!colorApplied && selfDetected) { - newColor = [_editor->config blockquoteColor]; + newColor = [_input->config blockquoteColor]; } if(newColor != nullptr) { - [_editor->textView.textStorage addAttribute:NSForegroundColorAttributeName value:newColor range:currRange]; - [_editor->textView.textStorage addAttribute:NSUnderlineColorAttributeName value:newColor range:currRange]; - [_editor->textView.textStorage addAttribute:NSStrikethroughColorAttributeName value:newColor range:currRange]; + [_input->textView.textStorage addAttribute:NSForegroundColorAttributeName value:newColor range:currRange]; + [_input->textView.textStorage addAttribute:NSUnderlineColorAttributeName value:newColor range:currRange]; + [_input->textView.textStorage addAttribute:NSStrikethroughColorAttributeName value:newColor range:currRange]; } } ]; diff --git a/ios/styles/BoldStyle.mm b/ios/styles/BoldStyle.mm index 6c4e447b4..075c856a9 100644 --- a/ios/styles/BoldStyle.mm +++ b/ios/styles/BoldStyle.mm @@ -1,17 +1,17 @@ #import "StyleHeaders.h" -#import "ReactNativeRichTextEditorView.h" +#import "EnrichedTextInputView.h" #import "FontExtension.h" #import "OccurenceUtils.h" @implementation BoldStyle { - ReactNativeRichTextEditorView *_editor; + EnrichedTextInputView *_input; } + (StyleType)getStyleType { return Bold; } -- (instancetype)initWithEditor:(id)editor { +- (instancetype)initWithInput:(id)input { self = [super init]; - _editor = (ReactNativeRichTextEditorView *) editor; + _input = (EnrichedTextInputView *)input; return self; } @@ -25,61 +25,61 @@ - (void)applyStyle:(NSRange)range { } - (void)addAttributes:(NSRange)range { - [_editor->textView.textStorage beginEditing]; - [_editor->textView.textStorage enumerateAttribute:NSFontAttributeName inRange:range options:0 + [_input->textView.textStorage beginEditing]; + [_input->textView.textStorage enumerateAttribute:NSFontAttributeName inRange:range options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { UIFont *font = (UIFont *)value; if(font != nullptr) { UIFont *newFont = [font setBold]; - [_editor->textView.textStorage addAttribute:NSFontAttributeName value:newFont range:range]; + [_input->textView.textStorage addAttribute:NSFontAttributeName value:newFont range:range]; } } ]; - [_editor->textView.textStorage endEditing]; + [_input->textView.textStorage endEditing]; } - (void)addTypingAttributes { - UIFont *currentFontAttr = (UIFont *)_editor->textView.typingAttributes[NSFontAttributeName]; + UIFont *currentFontAttr = (UIFont *)_input->textView.typingAttributes[NSFontAttributeName]; if(currentFontAttr != nullptr) { - NSMutableDictionary *newTypingAttrs = [_editor->textView.typingAttributes mutableCopy]; + NSMutableDictionary *newTypingAttrs = [_input->textView.typingAttributes mutableCopy]; newTypingAttrs[NSFontAttributeName] = [currentFontAttr setBold]; - _editor->textView.typingAttributes = newTypingAttrs; + _input->textView.typingAttributes = newTypingAttrs; } } - (void)removeAttributes:(NSRange)range { - [_editor->textView.textStorage beginEditing]; - [_editor->textView.textStorage enumerateAttribute:NSFontAttributeName inRange:range options:0 + [_input->textView.textStorage beginEditing]; + [_input->textView.textStorage enumerateAttribute:NSFontAttributeName inRange:range options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { UIFont *font = (UIFont *)value; if(font != nullptr) { UIFont *newFont = [font removeBold]; - [_editor->textView.textStorage addAttribute:NSFontAttributeName value:newFont range:range]; + [_input->textView.textStorage addAttribute:NSFontAttributeName value:newFont range:range]; } } ]; - [_editor->textView.textStorage endEditing]; + [_input->textView.textStorage endEditing]; } - (void)removeTypingAttributes { - UIFont *currentFontAttr = (UIFont *)_editor->textView.typingAttributes[NSFontAttributeName]; + UIFont *currentFontAttr = (UIFont *)_input->textView.typingAttributes[NSFontAttributeName]; if(currentFontAttr != nullptr) { - NSMutableDictionary *newTypingAttrs = [_editor->textView.typingAttributes mutableCopy]; + NSMutableDictionary *newTypingAttrs = [_input->textView.typingAttributes mutableCopy]; newTypingAttrs[NSFontAttributeName] = [currentFontAttr removeBold]; - _editor->textView.typingAttributes = newTypingAttrs; + _input->textView.typingAttributes = newTypingAttrs; } } - (BOOL)boldHeadingConflictsInRange:(NSRange)range type:(StyleType)type { if(type == H1) { - if(![_editor->config h1Bold]) { return NO; } + if(![_input->config h1Bold]) { return NO; } } else if(type == H2) { - if(![_editor->config h2Bold]) { return NO; } + if(![_input->config h2Bold]) { return NO; } } else if(type == H3) { - if(![_editor->config h3Bold]) { return NO; } + if(![_input->config h3Bold]) { return NO; } } - id headingStyle = _editor->stylesDict[@(type)]; + id headingStyle = _input->stylesDict[@(type)]; return range.length > 0 ? [headingStyle anyOccurence:range] : [headingStyle detectStyle:range]; @@ -92,19 +92,19 @@ - (BOOL)styleCondition:(id _Nullable)value :(NSRange)range { - (BOOL)detectStyle:(NSRange)range { if(range.length >= 1) { - return [OccurenceUtils detect:NSFontAttributeName withEditor:_editor inRange:range + return [OccurenceUtils detect:NSFontAttributeName withInput:_input inRange:range withCondition: ^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } ]; } else { - UIFont *currentFontAttr = (UIFont *)_editor->textView.typingAttributes[NSFontAttributeName]; + UIFont *currentFontAttr = (UIFont *)_input->textView.typingAttributes[NSFontAttributeName]; return [self styleCondition:currentFontAttr :range]; } } - (BOOL)anyOccurence:(NSRange)range { - return [OccurenceUtils any:NSFontAttributeName withEditor:_editor inRange:range + return [OccurenceUtils any:NSFontAttributeName withInput:_input inRange:range withCondition:^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } @@ -112,7 +112,7 @@ - (BOOL)anyOccurence:(NSRange)range { } - (NSArray *_Nullable)findAllOccurences:(NSRange)range { - return [OccurenceUtils all:NSFontAttributeName withEditor:_editor inRange:range + return [OccurenceUtils all:NSFontAttributeName withInput:_input inRange:range withCondition:^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } diff --git a/ios/styles/H1Style.mm b/ios/styles/H1Style.mm index 2997ba319..9a8c4dedd 100644 --- a/ios/styles/H1Style.mm +++ b/ios/styles/H1Style.mm @@ -1,10 +1,10 @@ #import "StyleHeaders.h" -#import "ReactNativeRichTextEditorView.h" +#import "EnrichedTextInputView.h" @implementation H1Style + (StyleType)getStyleType { return H1; } -- (CGFloat)getHeadingFontSize { return [((ReactNativeRichTextEditorView *)editor)->config h1FontSize]; } +- (CGFloat)getHeadingFontSize { return [((EnrichedTextInputView *)input)->config h1FontSize]; } - (BOOL)isHeadingBold { - return [((ReactNativeRichTextEditorView *)editor)->config h1Bold]; + return [((EnrichedTextInputView *)input)->config h1Bold]; } @end diff --git a/ios/styles/H2Style.mm b/ios/styles/H2Style.mm index 27b481373..1913c2f30 100644 --- a/ios/styles/H2Style.mm +++ b/ios/styles/H2Style.mm @@ -1,10 +1,10 @@ #import "StyleHeaders.h" -#import "ReactNativeRichTextEditorView.h" +#import "EnrichedTextInputView.h" @implementation H2Style + (StyleType)getStyleType { return H2; } -- (CGFloat)getHeadingFontSize { return [((ReactNativeRichTextEditorView *)editor)->config h2FontSize]; } +- (CGFloat)getHeadingFontSize { return [((EnrichedTextInputView *)input)->config h2FontSize]; } - (BOOL)isHeadingBold { - return [((ReactNativeRichTextEditorView *)editor)->config h2Bold]; + return [((EnrichedTextInputView *)input)->config h2Bold]; } @end diff --git a/ios/styles/H3Style.mm b/ios/styles/H3Style.mm index 8a5d32e3b..f7b55bc7f 100644 --- a/ios/styles/H3Style.mm +++ b/ios/styles/H3Style.mm @@ -1,10 +1,10 @@ #import "StyleHeaders.h" -#import "ReactNativeRichTextEditorView.h" +#import "EnrichedTextInputView.h" @implementation H3Style + (StyleType)getStyleType { return H3; } -- (CGFloat)getHeadingFontSize { return [((ReactNativeRichTextEditorView *)editor)->config h3FontSize]; } +- (CGFloat)getHeadingFontSize { return [((EnrichedTextInputView *)input)->config h3FontSize]; } - (BOOL)isHeadingBold { - return [((ReactNativeRichTextEditorView *)editor)->config h3Bold]; + return [((EnrichedTextInputView *)input)->config h3Bold]; } @end diff --git a/ios/styles/HeadingStyleBase.mm b/ios/styles/HeadingStyleBase.mm index afb800ba4..632eb5781 100644 --- a/ios/styles/HeadingStyleBase.mm +++ b/ios/styles/HeadingStyleBase.mm @@ -1,5 +1,5 @@ #import "StyleHeaders.h" -#import "ReactNativeRichTextEditorView.h" +#import "EnrichedTextInputView.h" #import "FontExtension.h" #import "OccurenceUtils.h" @@ -10,13 +10,13 @@ + (StyleType)getStyleType { return None; } - (CGFloat)getHeadingFontSize { return 0; } - (BOOL)isHeadingBold { return false; } -- (ReactNativeRichTextEditorView *)typedEditor { - return (ReactNativeRichTextEditorView *)editor; +- (EnrichedTextInputView *)typedInput { + return (EnrichedTextInputView *)input; } -- (instancetype)initWithEditor:(id)editor { +- (instancetype)initWithInput:(id)input { self = [super init]; - self->editor = editor; + self->input = input; return self; } @@ -33,8 +33,8 @@ - (void)applyStyle:(NSRange)range { // the range will already be the proper full paragraph/s range - (void)addAttributes:(NSRange)range { - [[self typedEditor]->textView.textStorage beginEditing]; - [[self typedEditor]->textView.textStorage enumerateAttribute:NSFontAttributeName inRange:range options:0 + [[self typedInput]->textView.textStorage beginEditing]; + [[self typedInput]->textView.textStorage enumerateAttribute:NSFontAttributeName inRange:range options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { UIFont *font = (UIFont *)value; if(font != nullptr) { @@ -42,11 +42,11 @@ - (void)addAttributes:(NSRange)range { if([self isHeadingBold]) { newFont = [newFont setBold]; } - [[self typedEditor]->textView.textStorage addAttribute:NSFontAttributeName value:newFont range:range]; + [[self typedInput]->textView.textStorage addAttribute:NSFontAttributeName value:newFont range:range]; } } ]; - [[self typedEditor]->textView.textStorage endEditing]; + [[self typedInput]->textView.textStorage endEditing]; // also toggle typing attributes [self addTypingAttributes]; @@ -54,53 +54,53 @@ - (void)addAttributes:(NSRange)range { // will always be called on empty paragraphs so only typing attributes can be changed - (void)addTypingAttributes { - UIFont *currentFontAttr = (UIFont *)[self typedEditor]->textView.typingAttributes[NSFontAttributeName]; + UIFont *currentFontAttr = (UIFont *)[self typedInput]->textView.typingAttributes[NSFontAttributeName]; if(currentFontAttr != nullptr) { - NSMutableDictionary *newTypingAttrs = [[self typedEditor]->textView.typingAttributes mutableCopy]; + NSMutableDictionary *newTypingAttrs = [[self typedInput]->textView.typingAttributes mutableCopy]; UIFont *newFont = [currentFontAttr setSize:[self getHeadingFontSize]]; if([self isHeadingBold]) { newFont = [newFont setBold]; } newTypingAttrs[NSFontAttributeName] = newFont; - [self typedEditor]->textView.typingAttributes = newTypingAttrs; + [self typedInput]->textView.typingAttributes = newTypingAttrs; } } // we need to remove the style from the whole paragraph - (void)removeAttributes:(NSRange)range { - NSRange paragraphRange = [[self typedEditor]->textView.textStorage.string paragraphRangeForRange:range]; + NSRange paragraphRange = [[self typedInput]->textView.textStorage.string paragraphRangeForRange:range]; - [[self typedEditor]->textView.textStorage beginEditing]; - [[self typedEditor]->textView.textStorage enumerateAttribute:NSFontAttributeName inRange:paragraphRange options:0 + [[self typedInput]->textView.textStorage beginEditing]; + [[self typedInput]->textView.textStorage enumerateAttribute:NSFontAttributeName inRange:paragraphRange options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { if([self styleCondition:value :range]) { - UIFont *newFont = [(UIFont *)value setSize:[[[self typedEditor]->config primaryFontSize] floatValue]]; + UIFont *newFont = [(UIFont *)value setSize:[[[self typedInput]->config primaryFontSize] floatValue]]; if([self isHeadingBold]) { newFont = [newFont removeBold]; } - [[self typedEditor]->textView.textStorage addAttribute:NSFontAttributeName value:newFont range:range]; + [[self typedInput]->textView.textStorage addAttribute:NSFontAttributeName value:newFont range:range]; } } ]; - [[self typedEditor]->textView.textStorage endEditing]; + [[self typedInput]->textView.textStorage endEditing]; // typing attributes still need to be removed - UIFont *currentFontAttr = (UIFont *)[self typedEditor]->textView.typingAttributes[NSFontAttributeName]; + UIFont *currentFontAttr = (UIFont *)[self typedInput]->textView.typingAttributes[NSFontAttributeName]; if(currentFontAttr != nullptr) { - NSMutableDictionary *newTypingAttrs = [[self typedEditor]->textView.typingAttributes mutableCopy]; - UIFont *newFont = [currentFontAttr setSize:[[[self typedEditor]->config primaryFontSize] floatValue]]; + NSMutableDictionary *newTypingAttrs = [[self typedInput]->textView.typingAttributes mutableCopy]; + UIFont *newFont = [currentFontAttr setSize:[[[self typedInput]->config primaryFontSize] floatValue]]; if([self isHeadingBold]) { newFont = [newFont removeBold]; } newTypingAttrs[NSFontAttributeName] = newFont; - [self typedEditor]->textView.typingAttributes = newTypingAttrs; + [self typedInput]->textView.typingAttributes = newTypingAttrs; } } - (void)removeTypingAttributes { // all the heading still needs to be removed because this function may be called in conflicting styles logic // typing attributes already get removed in there as well - [self removeAttributes:[self typedEditor]->textView.selectedRange]; + [self removeAttributes:[self typedInput]->textView.selectedRange]; } - (BOOL)styleCondition:(id _Nullable)value :(NSRange)range { @@ -110,13 +110,13 @@ - (BOOL)styleCondition:(id _Nullable)value :(NSRange)range { - (BOOL)detectStyle:(NSRange)range { if(range.length >= 1) { - return [OccurenceUtils detect:NSFontAttributeName withEditor:[self typedEditor] inRange:range + return [OccurenceUtils detect:NSFontAttributeName withInput:[self typedInput] inRange:range withCondition: ^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } ]; } else { - UIFont *currentFontAttr = (UIFont *)[self typedEditor]->textView.typingAttributes[NSFontAttributeName]; + UIFont *currentFontAttr = (UIFont *)[self typedInput]->textView.typingAttributes[NSFontAttributeName]; if(currentFontAttr == nullptr) { return false; } @@ -125,7 +125,7 @@ - (BOOL)detectStyle:(NSRange)range { } - (BOOL)anyOccurence:(NSRange)range { - return [OccurenceUtils any:NSFontAttributeName withEditor:[self typedEditor] inRange:range + return [OccurenceUtils any:NSFontAttributeName withInput:[self typedInput] inRange:range withCondition:^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } @@ -133,7 +133,7 @@ - (BOOL)anyOccurence:(NSRange)range { } - (NSArray *_Nullable)findAllOccurences:(NSRange)range { - return [OccurenceUtils all:NSFontAttributeName withEditor:[self typedEditor] inRange:range + return [OccurenceUtils all:NSFontAttributeName withInput:[self typedInput] inRange:range withCondition:^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } diff --git a/ios/styles/InlineCodeStyle.mm b/ios/styles/InlineCodeStyle.mm index 87cec412c..b0cdd8070 100644 --- a/ios/styles/InlineCodeStyle.mm +++ b/ios/styles/InlineCodeStyle.mm @@ -1,18 +1,18 @@ #import "StyleHeaders.h" -#import "ReactNativeRichTextEditorView.h" +#import "EnrichedTextInputView.h" #import "FontExtension.h" #import "OccurenceUtils.h" #import "ParagraphsUtils.h" @implementation InlineCodeStyle { - ReactNativeRichTextEditorView *_editor; + EnrichedTextInputView *_input; } + (StyleType)getStyleType { return InlineCode; } -- (instancetype)initWithEditor:(id)editor { +- (instancetype)initWithInput:(id)input { self = [super init]; - _editor = (ReactNativeRichTextEditorView *) editor; + _input = (EnrichedTextInputView *)input; return self; } @@ -27,83 +27,83 @@ - (void)applyStyle:(NSRange)range { - (void)addAttributes:(NSRange)range { // we don't want to apply inline code to newline characters, it looks bad - NSArray *nonNewlineRanges = [ParagraphsUtils getNonNewlineRangesIn:_editor->textView range:range]; + NSArray *nonNewlineRanges = [ParagraphsUtils getNonNewlineRangesIn:_input->textView range:range]; for(NSValue *value in nonNewlineRanges) { NSRange currentRange = [value rangeValue]; - [_editor->textView.textStorage beginEditing]; + [_input->textView.textStorage beginEditing]; - [_editor->textView.textStorage addAttribute:NSBackgroundColorAttributeName value:[[_editor->config inlineCodeBgColor] colorWithAlphaComponent:0.4] range:currentRange]; - [_editor->textView.textStorage addAttribute:NSForegroundColorAttributeName value:[_editor->config inlineCodeFgColor] range:currentRange]; - [_editor->textView.textStorage addAttribute:NSUnderlineColorAttributeName value:[_editor->config inlineCodeFgColor] range:currentRange]; - [_editor->textView.textStorage addAttribute:NSStrikethroughColorAttributeName value:[_editor->config inlineCodeFgColor] range:currentRange]; - [_editor->textView.textStorage enumerateAttribute:NSFontAttributeName inRange:currentRange options:0 + [_input->textView.textStorage addAttribute:NSBackgroundColorAttributeName value:[[_input->config inlineCodeBgColor] colorWithAlphaComponent:0.4] range:currentRange]; + [_input->textView.textStorage addAttribute:NSForegroundColorAttributeName value:[_input->config inlineCodeFgColor] range:currentRange]; + [_input->textView.textStorage addAttribute:NSUnderlineColorAttributeName value:[_input->config inlineCodeFgColor] range:currentRange]; + [_input->textView.textStorage addAttribute:NSStrikethroughColorAttributeName value:[_input->config inlineCodeFgColor] range:currentRange]; + [_input->textView.textStorage enumerateAttribute:NSFontAttributeName inRange:currentRange options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { UIFont *font = (UIFont *)value; if(font != nullptr) { - UIFont *newFont = [[_editor->config monospacedFont] withFontTraits:font]; - [_editor->textView.textStorage addAttribute:NSFontAttributeName value:newFont range:range]; + UIFont *newFont = [[_input->config monospacedFont] withFontTraits:font]; + [_input->textView.textStorage addAttribute:NSFontAttributeName value:newFont range:range]; } } ]; - [_editor->textView.textStorage endEditing]; + [_input->textView.textStorage endEditing]; } } - (void)addTypingAttributes { - NSMutableDictionary *newTypingAttrs = [_editor->textView.typingAttributes mutableCopy]; - newTypingAttrs[NSBackgroundColorAttributeName] = [[_editor->config inlineCodeBgColor] colorWithAlphaComponent:0.4]; - newTypingAttrs[NSForegroundColorAttributeName] = [_editor->config inlineCodeFgColor]; - newTypingAttrs[NSUnderlineColorAttributeName] = [_editor->config inlineCodeFgColor]; - newTypingAttrs[NSStrikethroughColorAttributeName] = [_editor->config inlineCodeFgColor]; + NSMutableDictionary *newTypingAttrs = [_input->textView.typingAttributes mutableCopy]; + newTypingAttrs[NSBackgroundColorAttributeName] = [[_input->config inlineCodeBgColor] colorWithAlphaComponent:0.4]; + newTypingAttrs[NSForegroundColorAttributeName] = [_input->config inlineCodeFgColor]; + newTypingAttrs[NSUnderlineColorAttributeName] = [_input->config inlineCodeFgColor]; + newTypingAttrs[NSStrikethroughColorAttributeName] = [_input->config inlineCodeFgColor]; UIFont* currentFont = (UIFont *)newTypingAttrs[NSFontAttributeName]; if(currentFont != nullptr) { - newTypingAttrs[NSFontAttributeName] = [[_editor->config monospacedFont] withFontTraits:currentFont]; + newTypingAttrs[NSFontAttributeName] = [[_input->config monospacedFont] withFontTraits:currentFont]; } - _editor->textView.typingAttributes = newTypingAttrs; + _input->textView.typingAttributes = newTypingAttrs; } - (void)removeAttributes:(NSRange)range { - [_editor->textView.textStorage beginEditing]; + [_input->textView.textStorage beginEditing]; - [_editor->textView.textStorage removeAttribute:NSBackgroundColorAttributeName range:range]; - [_editor->textView.textStorage addAttribute:NSForegroundColorAttributeName value:[_editor->config primaryColor] range:range]; - [_editor->textView.textStorage addAttribute:NSUnderlineColorAttributeName value:[_editor->config primaryColor] range:range]; - [_editor->textView.textStorage addAttribute:NSStrikethroughColorAttributeName value:[_editor->config primaryColor] range:range]; - [_editor->textView.textStorage enumerateAttribute:NSFontAttributeName inRange:range options:0 + [_input->textView.textStorage removeAttribute:NSBackgroundColorAttributeName range:range]; + [_input->textView.textStorage addAttribute:NSForegroundColorAttributeName value:[_input->config primaryColor] range:range]; + [_input->textView.textStorage addAttribute:NSUnderlineColorAttributeName value:[_input->config primaryColor] range:range]; + [_input->textView.textStorage addAttribute:NSStrikethroughColorAttributeName value:[_input->config primaryColor] range:range]; + [_input->textView.textStorage enumerateAttribute:NSFontAttributeName inRange:range options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { UIFont *font = (UIFont *)value; if(font != nullptr) { - UIFont *newFont = [[_editor->config primaryFont] withFontTraits:font]; - [_editor->textView.textStorage addAttribute:NSFontAttributeName value:newFont range:range]; + UIFont *newFont = [[_input->config primaryFont] withFontTraits:font]; + [_input->textView.textStorage addAttribute:NSFontAttributeName value:newFont range:range]; } } ]; - [_editor->textView.textStorage endEditing]; + [_input->textView.textStorage endEditing]; } - (void)removeTypingAttributes { - NSMutableDictionary *newTypingAttrs = [_editor->textView.typingAttributes mutableCopy]; + NSMutableDictionary *newTypingAttrs = [_input->textView.typingAttributes mutableCopy]; [newTypingAttrs removeObjectForKey:NSBackgroundColorAttributeName]; - newTypingAttrs[NSForegroundColorAttributeName] = [_editor->config primaryColor]; - newTypingAttrs[NSUnderlineColorAttributeName] = [_editor->config primaryColor]; - newTypingAttrs[NSStrikethroughColorAttributeName] = [_editor->config primaryColor]; + newTypingAttrs[NSForegroundColorAttributeName] = [_input->config primaryColor]; + newTypingAttrs[NSUnderlineColorAttributeName] = [_input->config primaryColor]; + newTypingAttrs[NSStrikethroughColorAttributeName] = [_input->config primaryColor]; UIFont* currentFont = (UIFont *)newTypingAttrs[NSFontAttributeName]; if(currentFont != nullptr) { - newTypingAttrs[NSFontAttributeName] = [[_editor->config primaryFont] withFontTraits:currentFont]; + newTypingAttrs[NSFontAttributeName] = [[_input->config primaryFont] withFontTraits:currentFont]; } - _editor->textView.typingAttributes = newTypingAttrs; + _input->textView.typingAttributes = newTypingAttrs; } // making sure no newlines get inline code style, it looks bad - (void)handleNewlines { - for(int i = 0; i < _editor->textView.textStorage.string.length; i++) { - if([[NSCharacterSet newlineCharacterSet] characterIsMember:[_editor->textView.textStorage.string characterAtIndex:i]]) { + for(int i = 0; i < _input->textView.textStorage.string.length; i++) { + if([[NSCharacterSet newlineCharacterSet] characterIsMember:[_input->textView.textStorage.string characterAtIndex:i]]) { NSRange mockRange = NSMakeRange(0, 0); // can't use detect style because it intentionally doesn't take newlines into consideration - UIColor *bgColor = [_editor->textView.textStorage attribute:NSBackgroundColorAttributeName atIndex:i effectiveRange:&mockRange]; + UIColor *bgColor = [_input->textView.textStorage attribute:NSBackgroundColorAttributeName atIndex:i effectiveRange:&mockRange]; if([self styleCondition:bgColor :NSMakeRange(i, 1)]) { [self removeAttributes:NSMakeRange(i, 1)]; } @@ -114,14 +114,14 @@ - (void)handleNewlines { // emojis don't retain monospace font attribute so we check for the background color if there is no mention - (BOOL)styleCondition:(id _Nullable)value :(NSRange)range { UIColor *bgColor = (UIColor *)value; - MentionStyle *mStyle = _editor->stylesDict[@([MentionStyle getStyleType])]; + MentionStyle *mStyle = _input->stylesDict[@([MentionStyle getStyleType])]; return bgColor != nullptr && mStyle != nullptr && ![mStyle detectStyle:range]; } - (BOOL)detectStyle:(NSRange)range { if(range.length >= 1) { // detect only in non-newline characters - NSArray *nonNewlineRanges = [ParagraphsUtils getNonNewlineRangesIn:_editor->textView range:range]; + NSArray *nonNewlineRanges = [ParagraphsUtils getNonNewlineRangesIn:_input->textView range:range]; if(nonNewlineRanges.count == 0) { return NO; } @@ -129,7 +129,7 @@ - (BOOL)detectStyle:(NSRange)range { BOOL detected = YES; for(NSValue *value in nonNewlineRanges) { NSRange currentRange = [value rangeValue]; - BOOL currentDetected = [OccurenceUtils detect:NSBackgroundColorAttributeName withEditor:_editor inRange:currentRange + BOOL currentDetected = [OccurenceUtils detect:NSBackgroundColorAttributeName withInput:_input inRange:currentRange withCondition: ^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } @@ -139,13 +139,13 @@ - (BOOL)detectStyle:(NSRange)range { return detected; } else { - UIColor *currentBgColorAttr = (UIColor *)_editor->textView.typingAttributes[NSBackgroundColorAttributeName]; + UIColor *currentBgColorAttr = (UIColor *)_input->textView.typingAttributes[NSBackgroundColorAttributeName]; return [self styleCondition:currentBgColorAttr :range]; } } - (BOOL)anyOccurence:(NSRange)range { - return [OccurenceUtils any:NSBackgroundColorAttributeName withEditor:_editor inRange:range + return [OccurenceUtils any:NSBackgroundColorAttributeName withInput:_input inRange:range withCondition:^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } @@ -153,7 +153,7 @@ - (BOOL)anyOccurence:(NSRange)range { } - (NSArray *_Nullable)findAllOccurences:(NSRange)range { - return [OccurenceUtils all:NSBackgroundColorAttributeName withEditor:_editor inRange:range + return [OccurenceUtils all:NSBackgroundColorAttributeName withInput:_input inRange:range withCondition:^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } diff --git a/ios/styles/ItalicStyle.mm b/ios/styles/ItalicStyle.mm index 9c3fa8004..0a642f9e0 100644 --- a/ios/styles/ItalicStyle.mm +++ b/ios/styles/ItalicStyle.mm @@ -1,17 +1,17 @@ #import "StyleHeaders.h" -#import "ReactNativeRichTextEditorView.h" +#import "EnrichedTextInputView.h" #import "FontExtension.h" #import "OccurenceUtils.h" @implementation ItalicStyle { - ReactNativeRichTextEditorView *_editor; + EnrichedTextInputView *_input; } + (StyleType)getStyleType { return Italic; } -- (instancetype)initWithEditor:(id)editor { +- (instancetype)initWithInput:(id)input { self = [super init]; - _editor = (ReactNativeRichTextEditorView *) editor; + _input = (EnrichedTextInputView *)input; return self; } @@ -25,48 +25,48 @@ - (void)applyStyle:(NSRange)range { } - (void)addAttributes:(NSRange)range { - [_editor->textView.textStorage beginEditing]; - [_editor->textView.textStorage enumerateAttribute:NSFontAttributeName inRange:range options:0 + [_input->textView.textStorage beginEditing]; + [_input->textView.textStorage enumerateAttribute:NSFontAttributeName inRange:range options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { UIFont *font = (UIFont *)value; if(font != nullptr) { UIFont *newFont = [font setItalic]; - [_editor->textView.textStorage addAttribute:NSFontAttributeName value:newFont range:range]; + [_input->textView.textStorage addAttribute:NSFontAttributeName value:newFont range:range]; } } ]; - [_editor->textView.textStorage endEditing]; + [_input->textView.textStorage endEditing]; } - (void)addTypingAttributes { - UIFont *currentFontAttr = (UIFont *)_editor->textView.typingAttributes[NSFontAttributeName]; + UIFont *currentFontAttr = (UIFont *)_input->textView.typingAttributes[NSFontAttributeName]; if(currentFontAttr != nullptr) { - NSMutableDictionary *newTypingAttrs = [_editor->textView.typingAttributes mutableCopy]; + NSMutableDictionary *newTypingAttrs = [_input->textView.typingAttributes mutableCopy]; newTypingAttrs[NSFontAttributeName] = [currentFontAttr setItalic]; - _editor->textView.typingAttributes = newTypingAttrs; + _input->textView.typingAttributes = newTypingAttrs; } } - (void)removeAttributes:(NSRange)range { - [_editor->textView.textStorage beginEditing]; - [_editor->textView.textStorage enumerateAttribute:NSFontAttributeName inRange:range options:0 + [_input->textView.textStorage beginEditing]; + [_input->textView.textStorage enumerateAttribute:NSFontAttributeName inRange:range options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { UIFont *font = (UIFont *)value; if(font != nullptr) { UIFont *newFont = [font removeItalic]; - [_editor->textView.textStorage addAttribute:NSFontAttributeName value:newFont range:range]; + [_input->textView.textStorage addAttribute:NSFontAttributeName value:newFont range:range]; } } ]; - [_editor->textView.textStorage endEditing]; + [_input->textView.textStorage endEditing]; } - (void)removeTypingAttributes { - UIFont *currentFontAttr = (UIFont *)_editor->textView.typingAttributes[NSFontAttributeName]; + UIFont *currentFontAttr = (UIFont *)_input->textView.typingAttributes[NSFontAttributeName]; if(currentFontAttr != nullptr) { - NSMutableDictionary *newTypingAttrs = [_editor->textView.typingAttributes mutableCopy]; + NSMutableDictionary *newTypingAttrs = [_input->textView.typingAttributes mutableCopy]; newTypingAttrs[NSFontAttributeName] = [currentFontAttr removeItalic]; - _editor->textView.typingAttributes = newTypingAttrs; + _input->textView.typingAttributes = newTypingAttrs; } } @@ -77,13 +77,13 @@ - (BOOL)styleCondition:(id _Nullable)value :(NSRange)range { - (BOOL)detectStyle:(NSRange)range { if(range.length >= 1) { - return [OccurenceUtils detect:NSFontAttributeName withEditor:_editor inRange:range + return [OccurenceUtils detect:NSFontAttributeName withInput:_input inRange:range withCondition: ^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } ]; } else { - UIFont *currentFontAttr = (UIFont *)_editor->textView.typingAttributes[NSFontAttributeName]; + UIFont *currentFontAttr = (UIFont *)_input->textView.typingAttributes[NSFontAttributeName]; if(currentFontAttr == nullptr) { return false; } @@ -92,7 +92,7 @@ - (BOOL)detectStyle:(NSRange)range { } - (BOOL)anyOccurence:(NSRange)range { - return [OccurenceUtils any:NSFontAttributeName withEditor:_editor inRange:range + return [OccurenceUtils any:NSFontAttributeName withInput:_input inRange:range withCondition:^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } @@ -100,7 +100,7 @@ - (BOOL)anyOccurence:(NSRange)range { } - (NSArray *_Nullable)findAllOccurences:(NSRange)range { - return [OccurenceUtils all:NSFontAttributeName withEditor:_editor inRange:range + return [OccurenceUtils all:NSFontAttributeName withInput:_input inRange:range withCondition:^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } diff --git a/ios/styles/LinkStyle.mm b/ios/styles/LinkStyle.mm index b09a98304..82118e961 100644 --- a/ios/styles/LinkStyle.mm +++ b/ios/styles/LinkStyle.mm @@ -1,5 +1,5 @@ #import "StyleHeaders.h" -#import "ReactNativeRichTextEditorView.h" +#import "EnrichedTextInputView.h" #import "OccurenceUtils.h" #import "TextInsertionUtils.h" #import "UIView+React.h" @@ -10,14 +10,14 @@ static NSString *const AutomaticLinkAttributeName = @"AutomaticLinkAttributeName"; @implementation LinkStyle { - ReactNativeRichTextEditorView *_editor; + EnrichedTextInputView *_input; } + (StyleType)getStyleType { return Link; } -- (instancetype)initWithEditor:(id)editor { +- (instancetype)initWithInput:(id)input { self = [super init]; - _editor = (ReactNativeRichTextEditorView *) editor; + _input = (EnrichedTextInputView *)input; return self; } @@ -36,54 +36,54 @@ - (void)addTypingAttributes { // we have to make sure all links in the range get fully removed here - (void)removeAttributes:(NSRange)range { NSArray *links = [self findAllOccurences:range]; - [_editor->textView.textStorage beginEditing]; + [_input->textView.textStorage beginEditing]; for(StylePair *pair in links) { NSRange linkRange = [self getFullLinkRangeAt:[pair.rangeValue rangeValue].location]; - [_editor->textView.textStorage removeAttribute:ManualLinkAttributeName range:linkRange]; - [_editor->textView.textStorage removeAttribute:AutomaticLinkAttributeName range:linkRange]; - [_editor->textView.textStorage addAttribute:NSForegroundColorAttributeName value:[_editor->config primaryColor] range:linkRange]; - [_editor->textView.textStorage addAttribute:NSUnderlineColorAttributeName value:[_editor->config primaryColor] range:linkRange]; - [_editor->textView.textStorage addAttribute:NSStrikethroughColorAttributeName value:[_editor->config primaryColor] range:linkRange]; - if([_editor->config linkDecorationLine] == DecorationUnderline) { - [_editor->textView.textStorage removeAttribute:NSUnderlineStyleAttributeName range:linkRange]; + [_input->textView.textStorage removeAttribute:ManualLinkAttributeName range:linkRange]; + [_input->textView.textStorage removeAttribute:AutomaticLinkAttributeName range:linkRange]; + [_input->textView.textStorage addAttribute:NSForegroundColorAttributeName value:[_input->config primaryColor] range:linkRange]; + [_input->textView.textStorage addAttribute:NSUnderlineColorAttributeName value:[_input->config primaryColor] range:linkRange]; + [_input->textView.textStorage addAttribute:NSStrikethroughColorAttributeName value:[_input->config primaryColor] range:linkRange]; + if([_input->config linkDecorationLine] == DecorationUnderline) { + [_input->textView.textStorage removeAttribute:NSUnderlineStyleAttributeName range:linkRange]; } } - [_editor->textView.textStorage endEditing]; + [_input->textView.textStorage endEditing]; // adjust typing attributes as well - NSMutableDictionary *newTypingAttrs = [_editor->textView.typingAttributes mutableCopy]; - newTypingAttrs[NSForegroundColorAttributeName] = [_editor->config primaryColor]; - newTypingAttrs[NSUnderlineColorAttributeName] = [_editor->config primaryColor]; - newTypingAttrs[NSStrikethroughColorAttributeName] = [_editor->config primaryColor]; - if([_editor->config linkDecorationLine] == DecorationUnderline) { + NSMutableDictionary *newTypingAttrs = [_input->textView.typingAttributes mutableCopy]; + newTypingAttrs[NSForegroundColorAttributeName] = [_input->config primaryColor]; + newTypingAttrs[NSUnderlineColorAttributeName] = [_input->config primaryColor]; + newTypingAttrs[NSStrikethroughColorAttributeName] = [_input->config primaryColor]; + if([_input->config linkDecorationLine] == DecorationUnderline) { [newTypingAttrs removeObjectForKey:NSUnderlineStyleAttributeName]; } - _editor->textView.typingAttributes = newTypingAttrs; + _input->textView.typingAttributes = newTypingAttrs; } // used for conflicts, we have to remove the whole link - (void)removeTypingAttributes { - NSRange linkRange = [self getFullLinkRangeAt:_editor->textView.selectedRange.location]; - [_editor->textView.textStorage beginEditing]; - [_editor->textView.textStorage removeAttribute:ManualLinkAttributeName range:linkRange]; - [_editor->textView.textStorage removeAttribute:AutomaticLinkAttributeName range:linkRange]; - [_editor->textView.textStorage addAttribute:NSForegroundColorAttributeName value:[_editor->config primaryColor] range:linkRange]; - [_editor->textView.textStorage addAttribute:NSUnderlineColorAttributeName value:[_editor->config primaryColor] range:linkRange]; - [_editor->textView.textStorage addAttribute:NSStrikethroughColorAttributeName value:[_editor->config primaryColor] range:linkRange]; - if([_editor->config linkDecorationLine] == DecorationUnderline) { - [_editor->textView.textStorage removeAttribute:NSUnderlineStyleAttributeName range:linkRange]; + NSRange linkRange = [self getFullLinkRangeAt:_input->textView.selectedRange.location]; + [_input->textView.textStorage beginEditing]; + [_input->textView.textStorage removeAttribute:ManualLinkAttributeName range:linkRange]; + [_input->textView.textStorage removeAttribute:AutomaticLinkAttributeName range:linkRange]; + [_input->textView.textStorage addAttribute:NSForegroundColorAttributeName value:[_input->config primaryColor] range:linkRange]; + [_input->textView.textStorage addAttribute:NSUnderlineColorAttributeName value:[_input->config primaryColor] range:linkRange]; + [_input->textView.textStorage addAttribute:NSStrikethroughColorAttributeName value:[_input->config primaryColor] range:linkRange]; + if([_input->config linkDecorationLine] == DecorationUnderline) { + [_input->textView.textStorage removeAttribute:NSUnderlineStyleAttributeName range:linkRange]; } - [_editor->textView.textStorage endEditing]; + [_input->textView.textStorage endEditing]; // adjust typing attributes as well - NSMutableDictionary *newTypingAttrs = [_editor->textView.typingAttributes mutableCopy]; - newTypingAttrs[NSForegroundColorAttributeName] = [_editor->config primaryColor]; - newTypingAttrs[NSUnderlineColorAttributeName] = [_editor->config primaryColor]; - newTypingAttrs[NSStrikethroughColorAttributeName] = [_editor->config primaryColor]; - if([_editor->config linkDecorationLine] == DecorationUnderline) { + NSMutableDictionary *newTypingAttrs = [_input->textView.typingAttributes mutableCopy]; + newTypingAttrs[NSForegroundColorAttributeName] = [_input->config primaryColor]; + newTypingAttrs[NSUnderlineColorAttributeName] = [_input->config primaryColor]; + newTypingAttrs[NSStrikethroughColorAttributeName] = [_input->config primaryColor]; + if([_input->config linkDecorationLine] == DecorationUnderline) { [newTypingAttrs removeObjectForKey:NSUnderlineStyleAttributeName]; } - _editor->textView.typingAttributes = newTypingAttrs; + _input->textView.typingAttributes = newTypingAttrs; } - (BOOL)styleCondition:(id _Nullable)value :(NSRange)range { @@ -93,7 +93,7 @@ - (BOOL)styleCondition:(id _Nullable)value :(NSRange)range { - (BOOL)detectStyle:(NSRange)range { if(range.length >= 1) { - BOOL onlyLinks = [OccurenceUtils detectMultiple:@[ManualLinkAttributeName, AutomaticLinkAttributeName] withEditor:_editor inRange:range + BOOL onlyLinks = [OccurenceUtils detectMultiple:@[ManualLinkAttributeName, AutomaticLinkAttributeName] withInput:_input inRange:range withCondition: ^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } @@ -105,7 +105,7 @@ - (BOOL)detectStyle:(NSRange)range { } - (BOOL)anyOccurence:(NSRange)range { - return [OccurenceUtils anyMultiple:@[ManualLinkAttributeName, AutomaticLinkAttributeName] withEditor:_editor inRange:range + return [OccurenceUtils anyMultiple:@[ManualLinkAttributeName, AutomaticLinkAttributeName] withInput:_input inRange:range withCondition:^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } @@ -113,7 +113,7 @@ - (BOOL)anyOccurence:(NSRange)range { } - (NSArray *_Nullable)findAllOccurences:(NSRange)range { - return [OccurenceUtils allMultiple:@[ManualLinkAttributeName, AutomaticLinkAttributeName] withEditor:_editor inRange:range + return [OccurenceUtils allMultiple:@[ManualLinkAttributeName, AutomaticLinkAttributeName] withInput:_input inRange:range withCondition:^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } @@ -123,13 +123,13 @@ - (BOOL)anyOccurence:(NSRange)range { // MARK: - Public non-standard methods - (void)addLink:(NSString*)text url:(NSString*)url range:(NSRange)range manual:(BOOL)manual { - NSString *currentText = [_editor->textView.textStorage.string substringWithRange:range]; + NSString *currentText = [_input->textView.textStorage.string substringWithRange:range]; NSMutableDictionary *newAttrs = [[NSMutableDictionary alloc] init]; - newAttrs[NSForegroundColorAttributeName] = [_editor->config linkColor]; - newAttrs[NSUnderlineColorAttributeName] = [_editor->config linkColor]; - newAttrs[NSStrikethroughColorAttributeName] = [_editor->config linkColor]; - if([_editor->config linkDecorationLine] == DecorationUnderline) { + newAttrs[NSForegroundColorAttributeName] = [_input->config linkColor]; + newAttrs[NSUnderlineColorAttributeName] = [_input->config linkColor]; + newAttrs[NSStrikethroughColorAttributeName] = [_input->config linkColor]; + if([_input->config linkDecorationLine] == DecorationUnderline) { newAttrs[NSUnderlineStyleAttributeName] = @(NSUnderlineStyleSingle); } if(manual) { @@ -140,23 +140,23 @@ - (void)addLink:(NSString*)text url:(NSString*)url range:(NSRange)range manual:( if(range.length == 0) { // insert link - [TextInsertionUtils insertText:text at:range.location additionalAttributes:newAttrs editor:_editor withSelection:YES]; + [TextInsertionUtils insertText:text at:range.location additionalAttributes:newAttrs input:_input withSelection:YES]; } else if([currentText isEqualToString:text]) { // apply link attributes - [_editor->textView.textStorage addAttributes:newAttrs range:range]; + [_input->textView.textStorage addAttributes:newAttrs range:range]; // TextInsertionUtils take care of the selection but here we have to manually set it behind the link // ONLY with manual links, automatic ones don't need the selection fix if(manual) { - [_editor->textView reactFocus]; - _editor->textView.selectedRange = NSMakeRange(range.location + text.length, 0); + [_input->textView reactFocus]; + _input->textView.selectedRange = NSMakeRange(range.location + text.length, 0); } } else { // replace text with link - [TextInsertionUtils replaceText:text at:range additionalAttributes:newAttrs editor:_editor withSelection:YES]; + [TextInsertionUtils replaceText:text at:range additionalAttributes:newAttrs input:_input withSelection:YES]; } // mandatory connected links check - NSDictionary *currentWord = [WordsUtils getCurrentWord:_editor->textView.textStorage.string range:_editor->textView.selectedRange]; + NSDictionary *currentWord = [WordsUtils getCurrentWord:_input->textView.textStorage.string range:_input->textView.selectedRange]; if(currentWord != nullptr) { // get word properties NSString *wordText = (NSString *)[currentWord objectForKey:@"word"]; @@ -167,32 +167,32 @@ - (void)addLink:(NSString*)text url:(NSString*)url range:(NSRange)range manual:( } [self manageLinkTypingAttributes]; - [_editor anyTextMayHaveBeenModified]; + [_input anyTextMayHaveBeenModified]; } // get exact link data at the given location if it exists - (LinkData *)getLinkDataAt:(NSUInteger)location { NSRange manualLinkRange = NSMakeRange(0, 0); NSRange automaticLinkRange = NSMakeRange(0, 0); - NSRange editorRange = NSMakeRange(0, _editor->textView.textStorage.length); + NSRange inputRange = NSMakeRange(0, _input->textView.textStorage.length); // don't search at the very end of input NSUInteger searchLocation = location; - if(searchLocation == _editor->textView.textStorage.length) { + if(searchLocation == _input->textView.textStorage.length) { return nullptr; } - NSString *manualUrl = [_editor->textView.textStorage + NSString *manualUrl = [_input->textView.textStorage attribute:ManualLinkAttributeName atIndex:searchLocation longestEffectiveRange: &manualLinkRange - inRange:editorRange + inRange:inputRange ]; - NSString *automaticUrl = [_editor->textView.textStorage + NSString *automaticUrl = [_input->textView.textStorage attribute:AutomaticLinkAttributeName atIndex:searchLocation longestEffectiveRange: &automaticLinkRange - inRange:editorRange + inRange:inputRange ]; if((manualUrl == nullptr && automaticUrl == nullptr) || (manualLinkRange.length == 0 && automaticLinkRange.length == 0)) { @@ -204,7 +204,7 @@ - (LinkData *)getLinkDataAt:(NSUInteger)location { LinkData *data = [[LinkData alloc] init]; data.url = linkUrl; - data.text = [_editor->textView.textStorage.string substringWithRange:linkRange]; + data.text = [_input->textView.textStorage.string substringWithRange:linkRange]; return data; } @@ -212,11 +212,11 @@ - (LinkData *)getLinkDataAt:(NSUInteger)location { - (NSRange)getFullLinkRangeAt:(NSUInteger)location { NSRange manualLinkRange = NSMakeRange(0, 0); NSRange automaticLinkRange = NSMakeRange(0, 0); - NSRange editorRange = NSMakeRange(0, _editor->textView.textStorage.length); + NSRange inputRange = NSMakeRange(0, _input->textView.textStorage.length); // get the previous index if possible when at the very end of input NSUInteger searchLocation = location; - if(searchLocation == _editor->textView.textStorage.length) { + if(searchLocation == _input->textView.textStorage.length) { if(searchLocation == 0) { return NSMakeRange(0, 0); } else { @@ -224,17 +224,17 @@ - (NSRange)getFullLinkRangeAt:(NSUInteger)location { } } - [_editor->textView.textStorage + [_input->textView.textStorage attribute:ManualLinkAttributeName atIndex:searchLocation longestEffectiveRange: &manualLinkRange - inRange:editorRange + inRange:inputRange ]; - [_editor->textView.textStorage + [_input->textView.textStorage attribute:AutomaticLinkAttributeName atIndex:searchLocation longestEffectiveRange: &automaticLinkRange - inRange:editorRange + inRange:inputRange ]; return manualLinkRange.length == 0 ? automaticLinkRange : manualLinkRange; @@ -244,41 +244,41 @@ - (void)manageLinkTypingAttributes { // link's typing attribtues need to be removed at ALL times whenever we have some link around BOOL removeAttrs = NO; - if(_editor->textView.selectedRange.length == 0) { + if(_input->textView.selectedRange.length == 0) { // check before - if(_editor->textView.selectedRange.location >= 1) { - if([self detectStyle:NSMakeRange(_editor->textView.selectedRange.location - 1, 1)]) { + if(_input->textView.selectedRange.location >= 1) { + if([self detectStyle:NSMakeRange(_input->textView.selectedRange.location - 1, 1)]) { removeAttrs = YES; } } // check after - if(_editor->textView.selectedRange.location < _editor->textView.textStorage.length) { - if([self detectStyle:NSMakeRange(_editor->textView.selectedRange.location, 1)]) { + if(_input->textView.selectedRange.location < _input->textView.textStorage.length) { + if([self detectStyle:NSMakeRange(_input->textView.selectedRange.location, 1)]) { removeAttrs = YES; } } } else { - if([self anyOccurence:_editor->textView.selectedRange]) { + if([self anyOccurence:_input->textView.selectedRange]) { removeAttrs = YES; } } if(removeAttrs) { - NSMutableDictionary *newTypingAttrs = [_editor->textView.typingAttributes mutableCopy]; - newTypingAttrs[NSForegroundColorAttributeName] = [_editor->config primaryColor]; - newTypingAttrs[NSUnderlineColorAttributeName] = [_editor->config primaryColor]; - newTypingAttrs[NSStrikethroughColorAttributeName] = [_editor->config primaryColor]; - if([_editor->config linkDecorationLine] == DecorationUnderline) { + NSMutableDictionary *newTypingAttrs = [_input->textView.typingAttributes mutableCopy]; + newTypingAttrs[NSForegroundColorAttributeName] = [_input->config primaryColor]; + newTypingAttrs[NSUnderlineColorAttributeName] = [_input->config primaryColor]; + newTypingAttrs[NSStrikethroughColorAttributeName] = [_input->config primaryColor]; + if([_input->config linkDecorationLine] == DecorationUnderline) { [newTypingAttrs removeObjectForKey:NSUnderlineStyleAttributeName]; } - _editor->textView.typingAttributes = newTypingAttrs; + _input->textView.typingAttributes = newTypingAttrs; } } // handles detecting and removing automatic links - (void)handleAutomaticLinks:(NSString *)word inRange:(NSRange)wordRange { - InlineCodeStyle *inlineCodeStyle = [_editor->stylesDict objectForKey:@([InlineCodeStyle getStyleType])]; - MentionStyle *mentionStyle = [_editor->stylesDict objectForKey:@([MentionStyle getStyleType])]; + InlineCodeStyle *inlineCodeStyle = [_input->stylesDict objectForKey:@([InlineCodeStyle getStyleType])]; + MentionStyle *mentionStyle = [_input->stylesDict objectForKey:@([MentionStyle getStyleType])]; if (inlineCodeStyle == nullptr || mentionStyle == nullptr) { return; @@ -299,7 +299,7 @@ - (void)handleAutomaticLinks:(NSString *)word inRange:(NSRange)wordRange { // we don't recognize automatic links along manual ones __block BOOL manualLinkPresent = NO; - [_editor->textView.textStorage enumerateAttribute:ManualLinkAttributeName inRange:wordRange options:0 + [_input->textView.textStorage enumerateAttribute:ManualLinkAttributeName inRange:wordRange options:0 usingBlock:^(id value, NSRange range, BOOL *stop) { NSString *urlValue = (NSString *)value; if(urlValue != nullptr) { @@ -352,7 +352,7 @@ - (void)handleAutomaticLinks:(NSString *)word inRange:(NSRange)wordRange { } // emit onLinkDetected - [_editor emitOnLinkDetectedEvent:word url:regexPassedUrl range:wordRange]; + [_input emitOnLinkDetectedEvent:word url:regexPassedUrl range:wordRange]; } } @@ -364,7 +364,7 @@ - (void)handleManualLinks:(NSString *)word inRange:(NSRange)wordRange { __block NSInteger manualLinkMinIdx = -1; __block NSInteger manualLinkMaxIdx = -1; - [_editor->textView.textStorage enumerateAttribute:ManualLinkAttributeName inRange:wordRange options:0 + [_input->textView.textStorage enumerateAttribute:ManualLinkAttributeName inRange:wordRange options:0 usingBlock:^(id value, NSRange range, BOOL *stop) { NSString *urlValue = (NSString *)value; if (urlValue != nullptr) { @@ -392,13 +392,13 @@ - (void)handleManualLinks:(NSString *)word inRange:(NSRange)wordRange { // this way manual link gets "extended" only if some characters were added inside it if([manualLinkMinValue isEqualToString:manualLinkMaxValue]) { NSRange newRange = NSMakeRange(manualLinkMinIdx, manualLinkMaxIdx - manualLinkMinIdx + 1); - [_editor->textView.textStorage addAttribute:NSForegroundColorAttributeName value:[_editor->config linkColor] range:newRange]; - [_editor->textView.textStorage addAttribute:NSUnderlineColorAttributeName value:[_editor->config linkColor] range:newRange]; - [_editor->textView.textStorage addAttribute:NSStrikethroughColorAttributeName value:[_editor->config linkColor] range:newRange]; - if([_editor->config linkDecorationLine] == DecorationUnderline) { - [_editor->textView.textStorage addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:newRange]; + [_input->textView.textStorage addAttribute:NSForegroundColorAttributeName value:[_input->config linkColor] range:newRange]; + [_input->textView.textStorage addAttribute:NSUnderlineColorAttributeName value:[_input->config linkColor] range:newRange]; + [_input->textView.textStorage addAttribute:NSStrikethroughColorAttributeName value:[_input->config linkColor] range:newRange]; + if([_input->config linkDecorationLine] == DecorationUnderline) { + [_input->textView.textStorage addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:newRange]; } - [_editor->textView.textStorage addAttribute:ManualLinkAttributeName value:manualLinkMinValue range:newRange]; + [_input->textView.textStorage addAttribute:ManualLinkAttributeName value:manualLinkMinValue range:newRange]; } // link typing attributes need to be fixed after these changes @@ -408,12 +408,12 @@ - (void)handleManualLinks:(NSString *)word inRange:(NSRange)wordRange { // replacing whole input (that starts with a link) with a manually typed letter improperly applies link's attributes to all the following text - (BOOL)handleLeadingLinkReplacement:(NSRange)range replacementText:(NSString *)text { // whole textView range gets replaced with a single letter - if(_editor->textView.textStorage.string.length > 0 && NSEqualRanges(range, NSMakeRange(0, _editor->textView.textStorage.string.length)) && text.length == 1) { + if(_input->textView.textStorage.string.length > 0 && NSEqualRanges(range, NSMakeRange(0, _input->textView.textStorage.string.length)) && text.length == 1) { // first character detection is enough for the removal to be done if([self detectStyle:NSMakeRange(0, 1)]) { - [self removeAttributes:NSMakeRange(0, _editor->textView.textStorage.string.length)]; + [self removeAttributes:NSMakeRange(0, _input->textView.textStorage.string.length)]; // do the replacing manually - [TextInsertionUtils replaceText:text at:range additionalAttributes:nullptr editor:_editor withSelection:YES]; + [TextInsertionUtils replaceText:text at:range additionalAttributes:nullptr input:_input withSelection:YES]; return YES; } } @@ -429,12 +429,12 @@ - (BOOL)isSingleLinkIn:(NSRange)range { } - (void)removeConnectedLinksIfNeeded:(NSString *)word range:(NSRange)wordRange { - BOOL anyAutomatic = [OccurenceUtils any:AutomaticLinkAttributeName withEditor:_editor inRange:wordRange + BOOL anyAutomatic = [OccurenceUtils any:AutomaticLinkAttributeName withInput:_input inRange:wordRange withCondition: ^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } ]; - BOOL anyManual = [OccurenceUtils any:ManualLinkAttributeName withEditor:_editor inRange:wordRange + BOOL anyManual = [OccurenceUtils any:ManualLinkAttributeName withInput:_input inRange:wordRange withCondition: ^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } @@ -447,7 +447,7 @@ - (void)removeConnectedLinksIfNeeded:(NSString *)word range:(NSRange)wordRange { } // we are now sure there is only one type of link there - and make sure it covers the whole word - BOOL onlyLinks = [OccurenceUtils detectMultiple:@[ManualLinkAttributeName, AutomaticLinkAttributeName] withEditor:_editor inRange:wordRange + BOOL onlyLinks = [OccurenceUtils detectMultiple:@[ManualLinkAttributeName, AutomaticLinkAttributeName] withInput:_input inRange:wordRange withCondition: ^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } diff --git a/ios/styles/MentionStyle.mm b/ios/styles/MentionStyle.mm index f239df6df..673106a4d 100644 --- a/ios/styles/MentionStyle.mm +++ b/ios/styles/MentionStyle.mm @@ -1,5 +1,5 @@ #import "StyleHeaders.h" -#import "ReactNativeRichTextEditorView.h" +#import "EnrichedTextInputView.h" #import "OccurenceUtils.h" #import "TextInsertionUtils.h" #import "WordsUtils.h" @@ -9,7 +9,7 @@ static NSString *const MentionAttributeName = @"MentionAttributeName"; @implementation MentionStyle { - ReactNativeRichTextEditorView *_editor; + EnrichedTextInputView*_input; NSValue *_activeMentionRange; NSString *_activeMentionIndicator; BOOL _blockMentionEditing; @@ -17,9 +17,9 @@ @implementation MentionStyle { + (StyleType)getStyleType { return Mention; } -- (instancetype)initWithEditor:(id)editor { +- (instancetype)initWithInput:(id)input { self = [super init]; - _editor = (ReactNativeRichTextEditorView *) editor; + _input = (EnrichedTextInputView *)input; _activeMentionRange = nullptr; _activeMentionIndicator = nullptr; _blockMentionEditing = NO; @@ -43,60 +43,60 @@ - (void)removeAttributes:(NSRange)range { BOOL someMentionHadUnderline = NO; NSArray *mentions = [self findAllOccurences:range]; - [_editor->textView.textStorage beginEditing]; + [_input->textView.textStorage beginEditing]; for(StylePair *pair in mentions) { NSRange mentionRange = [self getFullMentionRangeAt:[pair.rangeValue rangeValue].location]; - [_editor->textView.textStorage removeAttribute:MentionAttributeName range:mentionRange]; - [_editor->textView.textStorage addAttribute:NSForegroundColorAttributeName value:[_editor->config primaryColor] range:mentionRange]; - [_editor->textView.textStorage addAttribute:NSUnderlineColorAttributeName value:[_editor->config primaryColor] range:mentionRange]; - [_editor->textView.textStorage addAttribute:NSStrikethroughColorAttributeName value:[_editor->config primaryColor] range:mentionRange]; - [_editor->textView.textStorage removeAttribute:NSBackgroundColorAttributeName range:mentionRange]; + [_input->textView.textStorage removeAttribute:MentionAttributeName range:mentionRange]; + [_input->textView.textStorage addAttribute:NSForegroundColorAttributeName value:[_input->config primaryColor] range:mentionRange]; + [_input->textView.textStorage addAttribute:NSUnderlineColorAttributeName value:[_input->config primaryColor] range:mentionRange]; + [_input->textView.textStorage addAttribute:NSStrikethroughColorAttributeName value:[_input->config primaryColor] range:mentionRange]; + [_input->textView.textStorage removeAttribute:NSBackgroundColorAttributeName range:mentionRange]; if([self stylePropsWithParams:pair.styleValue].decorationLine == DecorationUnderline) { - [_editor->textView.textStorage removeAttribute:NSUnderlineStyleAttributeName range:mentionRange]; + [_input->textView.textStorage removeAttribute:NSUnderlineStyleAttributeName range:mentionRange]; someMentionHadUnderline = YES; } } - [_editor->textView.textStorage endEditing]; + [_input->textView.textStorage endEditing]; // remove typing attributes as well - NSMutableDictionary *newTypingAttrs = [_editor->textView.typingAttributes mutableCopy]; - newTypingAttrs[NSForegroundColorAttributeName] = [_editor->config primaryColor]; - newTypingAttrs[NSUnderlineColorAttributeName] = [_editor->config primaryColor]; - newTypingAttrs[NSStrikethroughColorAttributeName] = [_editor->config primaryColor]; + NSMutableDictionary *newTypingAttrs = [_input->textView.typingAttributes mutableCopy]; + newTypingAttrs[NSForegroundColorAttributeName] = [_input->config primaryColor]; + newTypingAttrs[NSUnderlineColorAttributeName] = [_input->config primaryColor]; + newTypingAttrs[NSStrikethroughColorAttributeName] = [_input->config primaryColor]; [newTypingAttrs removeObjectForKey:NSBackgroundColorAttributeName]; if(someMentionHadUnderline) { [newTypingAttrs removeObjectForKey:NSUnderlineStyleAttributeName]; } - _editor->textView.typingAttributes = newTypingAttrs; + _input->textView.typingAttributes = newTypingAttrs; } // used for conflicts, we have to remove the whole mention - (void)removeTypingAttributes { - NSRange mentionRange = [self getFullMentionRangeAt:_editor->textView.selectedRange.location]; - [_editor->textView.textStorage beginEditing]; - [_editor->textView.textStorage removeAttribute:MentionAttributeName range:mentionRange]; - [_editor->textView.textStorage addAttribute:NSForegroundColorAttributeName value:[_editor->config primaryColor] range:mentionRange]; - [_editor->textView.textStorage addAttribute:NSUnderlineColorAttributeName value:[_editor->config primaryColor] range:mentionRange]; - [_editor->textView.textStorage addAttribute:NSStrikethroughColorAttributeName value:[_editor->config primaryColor] range:mentionRange]; - [_editor->textView.textStorage removeAttribute:NSBackgroundColorAttributeName range:mentionRange]; + NSRange mentionRange = [self getFullMentionRangeAt:_input->textView.selectedRange.location]; + [_input->textView.textStorage beginEditing]; + [_input->textView.textStorage removeAttribute:MentionAttributeName range:mentionRange]; + [_input->textView.textStorage addAttribute:NSForegroundColorAttributeName value:[_input->config primaryColor] range:mentionRange]; + [_input->textView.textStorage addAttribute:NSUnderlineColorAttributeName value:[_input->config primaryColor] range:mentionRange]; + [_input->textView.textStorage addAttribute:NSStrikethroughColorAttributeName value:[_input->config primaryColor] range:mentionRange]; + [_input->textView.textStorage removeAttribute:NSBackgroundColorAttributeName range:mentionRange]; MentionParams *params = [self getMentionParamsAt:mentionRange.location]; if([self stylePropsWithParams:params].decorationLine == DecorationUnderline) { - [_editor->textView.textStorage removeAttribute:NSUnderlineStyleAttributeName range:mentionRange]; + [_input->textView.textStorage removeAttribute:NSUnderlineStyleAttributeName range:mentionRange]; } - [_editor->textView.textStorage endEditing]; + [_input->textView.textStorage endEditing]; // remove typing attributes as well - NSMutableDictionary *newTypingAttrs = [_editor->textView.typingAttributes mutableCopy]; - newTypingAttrs[NSForegroundColorAttributeName] = [_editor->config primaryColor]; - newTypingAttrs[NSUnderlineColorAttributeName] = [_editor->config primaryColor]; - newTypingAttrs[NSStrikethroughColorAttributeName] = [_editor->config primaryColor]; + NSMutableDictionary *newTypingAttrs = [_input->textView.typingAttributes mutableCopy]; + newTypingAttrs[NSForegroundColorAttributeName] = [_input->config primaryColor]; + newTypingAttrs[NSUnderlineColorAttributeName] = [_input->config primaryColor]; + newTypingAttrs[NSStrikethroughColorAttributeName] = [_input->config primaryColor]; [newTypingAttrs removeObjectForKey:NSBackgroundColorAttributeName]; if([self stylePropsWithParams:params].decorationLine == DecorationUnderline) { [newTypingAttrs removeObjectForKey:NSUnderlineStyleAttributeName]; } - _editor->textView.typingAttributes = newTypingAttrs; + _input->textView.typingAttributes = newTypingAttrs; } - (BOOL)styleCondition:(id _Nullable)value :(NSRange)range { @@ -106,7 +106,7 @@ - (BOOL)styleCondition:(id _Nullable)value :(NSRange)range { - (BOOL)detectStyle:(NSRange)range { if(range.length >= 1) { - return [OccurenceUtils detect:MentionAttributeName withEditor:_editor inRange:range + return [OccurenceUtils detect:MentionAttributeName withInput:_input inRange:range withCondition: ^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } @@ -117,7 +117,7 @@ - (BOOL)detectStyle:(NSRange)range { } - (BOOL)anyOccurence:(NSRange)range { - return [OccurenceUtils any:MentionAttributeName withEditor:_editor inRange:range + return [OccurenceUtils any:MentionAttributeName withInput:_input inRange:range withCondition:^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } @@ -125,7 +125,7 @@ - (BOOL)anyOccurence:(NSRange)range { } - (NSArray *_Nullable)findAllOccurences:(NSRange)range { - return [OccurenceUtils all:MentionAttributeName withEditor:_editor inRange:range + return [OccurenceUtils all:MentionAttributeName withInput:_input inRange:range withCondition:^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } @@ -147,7 +147,7 @@ - (void)addMention:(NSString *)indicator text:(NSString *)text attributes:(NSStr params.indicator = indicator; params.attributes = attributes; - MentionStyleProps *styleProps = [_editor->config mentionStylePropsForIndicator:indicator]; + MentionStyleProps *styleProps = [_input->config mentionStylePropsForIndicator:indicator]; NSMutableDictionary *newAttrs = [@{ MentionAttributeName: params, @@ -164,10 +164,10 @@ - (void)addMention:(NSString *)indicator text:(NSString *)text attributes:(NSStr // add a single space after the mention NSString *newText = [NSString stringWithFormat:@"%@ ", text]; NSRange rangeToBeReplaced = [_activeMentionRange rangeValue]; - [TextInsertionUtils replaceText:newText at:rangeToBeReplaced additionalAttributes:nullptr editor:_editor withSelection:YES]; + [TextInsertionUtils replaceText:newText at:rangeToBeReplaced additionalAttributes:nullptr input:_input withSelection:YES]; // THEN, add the attributes to not apply them on the space - [_editor->textView.textStorage addAttributes:newAttrs range:NSMakeRange(rangeToBeReplaced.location, text.length)]; + [_input->textView.textStorage addAttributes:newAttrs range:NSMakeRange(rangeToBeReplaced.location, text.length)]; // mention editing should finish [self removeActiveMentionRange]; @@ -179,7 +179,7 @@ - (void)addMention:(NSString *)indicator text:(NSString *)text attributes:(NSStr - (void)addMentionAtRange:(NSRange)range params:(MentionParams *)params { _blockMentionEditing = YES; - MentionStyleProps *styleProps = [_editor->config mentionStylePropsForIndicator:params.indicator]; + MentionStyleProps *styleProps = [_input->config mentionStylePropsForIndicator:params.indicator]; NSMutableDictionary *newAttrs = [@{ MentionAttributeName: params, @@ -193,26 +193,26 @@ - (void)addMentionAtRange:(NSRange)range params:(MentionParams *)params { newAttrs[NSUnderlineStyleAttributeName] = @(NSUnderlineStyleSingle); } - [_editor->textView.textStorage addAttributes:newAttrs range:range]; + [_input->textView.textStorage addAttributes:newAttrs range:range]; _blockMentionEditing = NO; } - (void)startMentionWithIndicator:(NSString *)indicator { - NSRange currentRange = _editor->textView.selectedRange; + NSRange currentRange = _input->textView.selectedRange; BOOL addSpaceBefore = NO; BOOL addSpaceAfter = NO; if(currentRange.location > 0) { - unichar charBefore = [_editor->textView.textStorage.string characterAtIndex:(currentRange.location - 1)]; + unichar charBefore = [_input->textView.textStorage.string characterAtIndex:(currentRange.location - 1)]; if(![[NSCharacterSet whitespaceAndNewlineCharacterSet] characterIsMember:charBefore]) { addSpaceBefore = YES; } } - if(currentRange.location + currentRange.length < _editor->textView.textStorage.string.length) { - unichar charAfter = [_editor->textView.textStorage.string characterAtIndex:(currentRange.location + currentRange.length)]; + if(currentRange.location + currentRange.length < _input->textView.textStorage.string.length) { + unichar charAfter = [_input->textView.textStorage.string characterAtIndex:(currentRange.location + currentRange.length)]; if(![[NSCharacterSet whitespaceAndNewlineCharacterSet] characterIsMember:charAfter]) { addSpaceAfter = YES; } @@ -227,13 +227,13 @@ - (void)startMentionWithIndicator:(NSString *)indicator { NSRange newSelect = NSMakeRange(currentRange.location + finalString.length + (addSpaceAfter ? -1 : 0), 0); if(currentRange.length == 0) { - [TextInsertionUtils insertText:finalString at:currentRange.location additionalAttributes:nullptr editor:_editor withSelection:NO]; + [TextInsertionUtils insertText:finalString at:currentRange.location additionalAttributes:nullptr input:_input withSelection:NO]; } else { - [TextInsertionUtils replaceText:finalString at:currentRange additionalAttributes:nullptr editor:_editor withSelection:NO]; + [TextInsertionUtils replaceText:finalString at:currentRange additionalAttributes:nullptr input:_input withSelection:NO]; } - [_editor->textView reactFocus]; - _editor->textView.selectedRange = newSelect; + [_input->textView reactFocus]; + _input->textView.selectedRange = newSelect; } // handles removing no longer valid mentions @@ -241,7 +241,7 @@ - (void)handleExistingMentions { // unfortunately whole text needs to be checked for them // checking the modified words doesn't work because mention's text can have any number of spaces, which makes one mention any number of words long - NSRange wholeText = NSMakeRange(0, _editor->textView.textStorage.string.length); + NSRange wholeText = NSMakeRange(0, _input->textView.textStorage.string.length); // get menntions in ascending range.location order NSArray *mentions = [[self findAllOccurences:wholeText] sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) { NSRange range1 = [((StylePair *)obj1).rangeValue rangeValue]; @@ -272,7 +272,7 @@ - (void)handleExistingMentions { } // check for text, any modifications to it makes mention invalid - NSString *existingText = [_editor->textView.textStorage.string substringWithRange:currentRange]; + NSString *existingText = [_input->textView.textStorage.string substringWithRange:currentRange]; if(![existingText isEqualToString:currentText]) { [rangesToRemove addObject:[NSValue valueWithRange:currentRange]]; } @@ -291,14 +291,14 @@ - (void)manageMentionEditing { } // we don't take longer selections into consideration - if(_editor->textView.selectedRange.length > 0) { + if(_input->textView.selectedRange.length > 0) { [self removeActiveMentionRange]; return; } // get the current word if it exists // we can be using current word only thanks to the fact that ongoing mentions are always one word (in contrast to ready, added mentions) - NSDictionary *currentWord = [WordsUtils getCurrentWord:_editor->textView.textStorage.string range:_editor->textView.selectedRange]; + NSDictionary *currentWord = [WordsUtils getCurrentWord:_input->textView.textStorage.string range:_input->textView.selectedRange]; if(currentWord == nullptr) { [self removeActiveMentionRange]; return; @@ -315,7 +315,7 @@ - (void)manageMentionEditing { // check for mentionIndicators - no sign of them means we shouldn't be editing a mention unichar firstChar = [wordText characterAtIndex:0]; - if(![[_editor->config mentionIndicators] containsObject: @(firstChar)]) { + if(![[_input->config mentionIndicators] containsObject: @(firstChar)]) { [self removeActiveMentionRange]; return; } @@ -327,8 +327,8 @@ - (void)manageMentionEditing { } // get conflicting style classes - LinkStyle* linkStyle = [_editor->stylesDict objectForKey:@([LinkStyle getStyleType])]; - InlineCodeStyle* inlineCodeStyle = [_editor->stylesDict objectForKey:@([InlineCodeStyle getStyleType])]; + LinkStyle* linkStyle = [_input->stylesDict objectForKey:@([LinkStyle getStyleType])]; + InlineCodeStyle* inlineCodeStyle = [_input->stylesDict objectForKey:@([InlineCodeStyle getStyleType])]; if(linkStyle == nullptr || inlineCodeStyle == nullptr) { [self removeActiveMentionRange]; return; @@ -350,49 +350,49 @@ - (void)manageMentionTypingAttributes { BOOL removeAttrs = NO; MentionParams *params; - if(_editor->textView.selectedRange.length == 0) { + if(_input->textView.selectedRange.length == 0) { // check before - if(_editor->textView.selectedRange.location >= 1) { - if([self detectStyle:NSMakeRange(_editor->textView.selectedRange.location - 1, 1)]) { + if(_input->textView.selectedRange.location >= 1) { + if([self detectStyle:NSMakeRange(_input->textView.selectedRange.location - 1, 1)]) { removeAttrs = YES; - params = [self getMentionParamsAt:_editor->textView.selectedRange.location - 1]; + params = [self getMentionParamsAt:_input->textView.selectedRange.location - 1]; } } // check after - if(_editor->textView.selectedRange.location < _editor->textView.textStorage.length) { - if([self detectStyle:NSMakeRange(_editor->textView.selectedRange.location, 1)]) { + if(_input->textView.selectedRange.location < _input->textView.textStorage.length) { + if([self detectStyle:NSMakeRange(_input->textView.selectedRange.location, 1)]) { removeAttrs = YES; - params = [self getMentionParamsAt:_editor->textView.selectedRange.location]; + params = [self getMentionParamsAt:_input->textView.selectedRange.location]; } } } else { - if([self anyOccurence:_editor->textView.selectedRange]) { + if([self anyOccurence:_input->textView.selectedRange]) { removeAttrs = YES; } } if(removeAttrs) { - NSMutableDictionary *newTypingAttrs = [_editor->textView.typingAttributes mutableCopy]; - newTypingAttrs[NSForegroundColorAttributeName] = [_editor->config primaryColor]; - newTypingAttrs[NSUnderlineColorAttributeName] = [_editor->config primaryColor]; - newTypingAttrs[NSStrikethroughColorAttributeName] = [_editor->config primaryColor]; + NSMutableDictionary *newTypingAttrs = [_input->textView.typingAttributes mutableCopy]; + newTypingAttrs[NSForegroundColorAttributeName] = [_input->config primaryColor]; + newTypingAttrs[NSUnderlineColorAttributeName] = [_input->config primaryColor]; + newTypingAttrs[NSStrikethroughColorAttributeName] = [_input->config primaryColor]; [newTypingAttrs removeObjectForKey:NSBackgroundColorAttributeName]; if([self stylePropsWithParams:params].decorationLine == DecorationUnderline) { [newTypingAttrs removeObjectForKey:NSUnderlineStyleAttributeName]; } - _editor->textView.typingAttributes = newTypingAttrs; + _input->textView.typingAttributes = newTypingAttrs; } } // replacing whole input (that starts with a mention) with a manually typed letter improperly applies mention's attributes to all the following text - (BOOL)handleLeadingMentionReplacement:(NSRange)range replacementText:(NSString *)text { // whole textView range gets replaced with a single letter - if(_editor->textView.textStorage.string.length > 0 && NSEqualRanges(range, NSMakeRange(0, _editor->textView.textStorage.string.length)) && text.length == 1) { + if(_input->textView.textStorage.string.length > 0 && NSEqualRanges(range, NSMakeRange(0, _input->textView.textStorage.string.length)) && text.length == 1) { // first character detection is enough for the removal to be done if([self detectStyle:NSMakeRange(0, 1)]) { - [self removeAttributes:NSMakeRange(0, _editor->textView.textStorage.string.length)]; + [self removeAttributes:NSMakeRange(0, _input->textView.textStorage.string.length)]; // do the replacing manually - [TextInsertionUtils replaceText:text at:range additionalAttributes:nullptr editor:_editor withSelection:YES]; + [TextInsertionUtils replaceText:text at:range additionalAttributes:nullptr input:_input withSelection:YES]; return YES; } } @@ -402,19 +402,19 @@ - (BOOL)handleLeadingMentionReplacement:(NSRange)range replacementText:(NSString // returns mention params if it exists - (MentionParams *)getMentionParamsAt:(NSUInteger)location { NSRange mentionRange = NSMakeRange(0, 0); - NSRange editorRange = NSMakeRange(0, _editor->textView.textStorage.length); + NSRange inputRange = NSMakeRange(0, _input->textView.textStorage.length); // don't search at the very end of input NSUInteger searchLocation = location; - if(searchLocation == _editor->textView.textStorage.length) { + if(searchLocation == _input->textView.textStorage.length) { return nullptr; } - MentionParams *value = [_editor->textView.textStorage + MentionParams *value = [_input->textView.textStorage attribute:MentionAttributeName atIndex:searchLocation longestEffectiveRange: &mentionRange - inRange:editorRange + inRange:inputRange ]; return value; } @@ -426,11 +426,11 @@ - (NSValue *)getActiveMentionRange { // returns full range of a mention at some location - (NSRange)getFullMentionRangeAt:(NSUInteger)location { NSRange mentionRange = NSMakeRange(0, 0); - NSRange editorRange = NSMakeRange(0, _editor->textView.textStorage.length); + NSRange inputRange = NSMakeRange(0, _input->textView.textStorage.length); // get the previous index if possible when at the very end of input NSUInteger searchLocation = location; - if(searchLocation == _editor->textView.textStorage.length) { + if(searchLocation == _input->textView.textStorage.length) { if(searchLocation == 0) { return mentionRange; } else { @@ -438,11 +438,11 @@ - (NSRange)getFullMentionRangeAt:(NSUInteger)location { } } - [_editor->textView.textStorage + [_input->textView.textStorage attribute:MentionAttributeName atIndex:searchLocation longestEffectiveRange: &mentionRange - inRange:editorRange + inRange:inputRange ]; return mentionRange; } @@ -450,7 +450,7 @@ - (NSRange)getFullMentionRangeAt:(NSUInteger)location { // MARK: - Private non-standard methods - (MentionStyleProps *)stylePropsWithParams:(MentionParams *)params { - return [_editor->config mentionStylePropsForIndicator:params.indicator]; + return [_input->config mentionStylePropsForIndicator:params.indicator]; } // both used for setting the active mention range + indicator and fires proper onMention event @@ -459,7 +459,7 @@ - (void)setActiveMentionRange:(NSRange)range text:(NSString *)text { NSString *textString = [text substringWithRange:NSMakeRange(1, text.length - 1)]; _activeMentionIndicator = indicatorString; _activeMentionRange = [NSValue valueWithRange:range]; - [_editor emitOnMentionEvent:indicatorString text:textString]; + [_input emitOnMentionEvent:indicatorString text:textString]; } // removes stored mention range + indicator, which means that we no longer edit a mention and onMention event gets fired @@ -468,7 +468,7 @@ - (void)removeActiveMentionRange { NSString *indicatorCopy = [_activeMentionIndicator copy]; _activeMentionIndicator = nullptr; _activeMentionRange = nullptr; - [_editor emitOnMentionEvent:indicatorCopy text:nullptr]; + [_input emitOnMentionEvent:indicatorCopy text:nullptr]; } } diff --git a/ios/styles/OrderedListStyle.mm b/ios/styles/OrderedListStyle.mm index 947659362..832166476 100644 --- a/ios/styles/OrderedListStyle.mm +++ b/ios/styles/OrderedListStyle.mm @@ -1,12 +1,12 @@ #import "StyleHeaders.h" -#import "ReactNativeRichTextEditorView.h" +#import "EnrichedTextInputView.h" #import "FontExtension.h" #import "OccurenceUtils.h" #import "ParagraphsUtils.h" #import "TextInsertionUtils.h" @implementation OrderedListStyle { - ReactNativeRichTextEditorView *_editor; + EnrichedTextInputView *_input; } + (StyleType)getStyleType { return OrderedList; } @@ -14,12 +14,12 @@ + (StyleType)getStyleType { return OrderedList; } - (CGFloat)getHeadIndent { // lists are drawn manually // margin before marker + gap between marker and paragraph - return [_editor->config orderedListMarginLeft] + [_editor->config orderedListGapWidth]; + return [_input->config orderedListMarginLeft] + [_input->config orderedListGapWidth]; } -- (instancetype)initWithEditor:(id)editor { +- (instancetype)initWithInput:(id)input { self = [super init]; - _editor = (ReactNativeRichTextEditorView *) editor; + _input = (EnrichedTextInputView *)input; return self; } @@ -35,14 +35,14 @@ - (void)applyStyle:(NSRange)range { // we assume correct paragraph range is already given - (void)addAttributes:(NSRange)range { NSTextList *numberBullet = [[NSTextList alloc] initWithMarkerFormat:NSTextListMarkerDecimal options:0]; - NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:_editor->textView range:range]; + NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView range:range]; // if we fill empty lines with zero width spaces, we need to offset later ranges NSInteger offset = 0; // needed for range adjustments - NSRange preModificationRange = _editor->textView.selectedRange; + NSRange preModificationRange = _input->textView.selectedRange; // let's not emit some weird selection changes or text/html changes - _editor->blockEmitting = YES; + _input->blockEmitting = YES; for(NSValue *value in paragraphs) { // take previous offsets into consideration @@ -51,93 +51,93 @@ - (void)addAttributes:(NSRange)range { // length 0 with first line, length 1 and newline with some empty lines in the middle if(fixedRange.length == 0 || (fixedRange.length == 1 && - [[NSCharacterSet newlineCharacterSet] characterIsMember: [_editor->textView.textStorage.string characterAtIndex:fixedRange.location]]) + [[NSCharacterSet newlineCharacterSet] characterIsMember: [_input->textView.textStorage.string characterAtIndex:fixedRange.location]]) ) { - [TextInsertionUtils insertText:@"\u200B" at:fixedRange.location additionalAttributes:nullptr editor:_editor withSelection:NO]; + [TextInsertionUtils insertText:@"\u200B" at:fixedRange.location additionalAttributes:nullptr input:_input withSelection:NO]; fixedRange = NSMakeRange(fixedRange.location, fixedRange.length + 1); offset += 1; } - [_editor->textView.textStorage enumerateAttribute:NSParagraphStyleAttributeName inRange:fixedRange options:0 + [_input->textView.textStorage enumerateAttribute:NSParagraphStyleAttributeName inRange:fixedRange options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { NSMutableParagraphStyle *pStyle = [(NSParagraphStyle *)value mutableCopy]; pStyle.textLists = @[numberBullet]; pStyle.headIndent = [self getHeadIndent]; pStyle.firstLineHeadIndent = [self getHeadIndent]; - [_editor->textView.textStorage addAttribute:NSParagraphStyleAttributeName value:pStyle range:range]; + [_input->textView.textStorage addAttribute:NSParagraphStyleAttributeName value:pStyle range:range]; } ]; } // back to emitting - _editor->blockEmitting = NO; + _input->blockEmitting = NO; if(preModificationRange.length == 0) { // fix selection if only one line was possibly made a list and filled with a space - _editor->textView.selectedRange = preModificationRange; + _input->textView.selectedRange = preModificationRange; } else { // in other cases, fix the selection with newly made offsets - _editor->textView.selectedRange = NSMakeRange(preModificationRange.location, preModificationRange.length + offset); + _input->textView.selectedRange = NSMakeRange(preModificationRange.location, preModificationRange.length + offset); } // also add typing attributes - NSMutableDictionary *typingAttrs = [_editor->textView.typingAttributes mutableCopy]; + NSMutableDictionary *typingAttrs = [_input->textView.typingAttributes mutableCopy]; NSMutableParagraphStyle *pStyle = [typingAttrs[NSParagraphStyleAttributeName] mutableCopy]; pStyle.textLists = @[numberBullet]; pStyle.headIndent = [self getHeadIndent]; pStyle.firstLineHeadIndent = [self getHeadIndent]; typingAttrs[NSParagraphStyleAttributeName] = pStyle; - _editor->textView.typingAttributes = typingAttrs; + _input->textView.typingAttributes = typingAttrs; } // does pretty much the same as normal addAttributes, just need to get the range - (void)addTypingAttributes { - [self addAttributes:_editor->textView.selectedRange]; + [self addAttributes:_input->textView.selectedRange]; } - (void)removeAttributes:(NSRange)range { - NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:_editor->textView range:range]; + NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView range:range]; - [_editor->textView.textStorage beginEditing]; + [_input->textView.textStorage beginEditing]; for(NSValue *value in paragraphs) { NSRange range = [value rangeValue]; - [_editor->textView.textStorage enumerateAttribute:NSParagraphStyleAttributeName inRange:range options:0 + [_input->textView.textStorage enumerateAttribute:NSParagraphStyleAttributeName inRange:range options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { NSMutableParagraphStyle *pStyle = [(NSParagraphStyle *)value mutableCopy]; pStyle.textLists = @[]; pStyle.headIndent = 0; pStyle.firstLineHeadIndent = 0; - [_editor->textView.textStorage addAttribute:NSParagraphStyleAttributeName value:pStyle range:range]; + [_input->textView.textStorage addAttribute:NSParagraphStyleAttributeName value:pStyle range:range]; } ]; } - [_editor->textView.textStorage endEditing]; + [_input->textView.textStorage endEditing]; // also remove typing attributes - NSMutableDictionary *typingAttrs = [_editor->textView.typingAttributes mutableCopy]; + NSMutableDictionary *typingAttrs = [_input->textView.typingAttributes mutableCopy]; NSMutableParagraphStyle *pStyle = [typingAttrs[NSParagraphStyleAttributeName] mutableCopy]; pStyle.textLists = @[]; pStyle.headIndent = 0; pStyle.firstLineHeadIndent = 0; typingAttrs[NSParagraphStyleAttributeName] = pStyle; - _editor->textView.typingAttributes = typingAttrs; + _input->textView.typingAttributes = typingAttrs; } // needed for the sake of style conflicts, needs to do exactly the same as removeAttribtues - (void)removeTypingAttributes { - [self removeAttributes:_editor->textView.selectedRange]; + [self removeAttributes:_input->textView.selectedRange]; } // removing first list point by backspacing doesn't remove typing attributes because it doesn't run textViewDidChange // so we try guessing that a point should be deleted here - (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text { - if([self detectStyle:_editor->textView.selectedRange] && - NSEqualRanges(_editor->textView.selectedRange, NSMakeRange(0, 0)) && + if([self detectStyle:_input->textView.selectedRange] && + NSEqualRanges(_input->textView.selectedRange, NSMakeRange(0, 0)) && [text isEqualToString:@""] ) { - NSRange paragraphRange = [_editor->textView.textStorage.string paragraphRangeForRange:_editor->textView.selectedRange]; + NSRange paragraphRange = [_input->textView.textStorage.string paragraphRangeForRange:_input->textView.selectedRange]; [self removeAttributes:paragraphRange]; return YES; } @@ -145,24 +145,24 @@ - (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text { } - (BOOL)tryHandlingListShorcutInRange:(NSRange)range replacementText:(NSString *)text { - NSRange paragraphRange = [_editor->textView.textStorage.string paragraphRangeForRange:range]; + NSRange paragraphRange = [_input->textView.textStorage.string paragraphRangeForRange:range]; // a dot was added - check if we are both at the paragraph beginning + 1 character (which we want to be a dash) if([text isEqualToString:@"."] && range.location - 1 == paragraphRange.location) { - unichar charBefore = [_editor->textView.textStorage.string characterAtIndex:range.location - 1]; + unichar charBefore = [_input->textView.textStorage.string characterAtIndex:range.location - 1]; if(charBefore == '1') { // we got a match - add a list if possible - if([_editor handleStyleBlocksAndConflicts:[[self class] getStyleType] range:paragraphRange]) { + if([_input handleStyleBlocksAndConflicts:[[self class] getStyleType] range:paragraphRange]) { // don't emit some html updates during the replacing - BOOL prevEmitHtml = _editor->emitHtml; + BOOL prevEmitHtml = _input->emitHtml; if(prevEmitHtml) { - _editor->emitHtml = NO; + _input->emitHtml = NO; } // remove the number - [TextInsertionUtils replaceText:@"" at:NSMakeRange(paragraphRange.location, 1) additionalAttributes:nullptr editor:_editor withSelection:YES]; + [TextInsertionUtils replaceText:@"" at:NSMakeRange(paragraphRange.location, 1) additionalAttributes:nullptr input:_input withSelection:YES]; if(prevEmitHtml) { - _editor->emitHtml = YES; + _input->emitHtml = YES; } // add attributes on the paragraph @@ -181,25 +181,25 @@ - (BOOL)styleCondition:(id _Nullable)value :(NSRange)range { - (BOOL)detectStyle:(NSRange)range { if(range.length >= 1) { - return [OccurenceUtils detect:NSParagraphStyleAttributeName withEditor:_editor inRange:range + return [OccurenceUtils detect:NSParagraphStyleAttributeName withInput:_input inRange:range withCondition: ^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } ]; } else { NSInteger searchLocation = range.location; - if(searchLocation == _editor->textView.textStorage.length) { - NSParagraphStyle *pStyle = _editor->textView.typingAttributes[NSParagraphStyleAttributeName]; + if(searchLocation == _input->textView.textStorage.length) { + NSParagraphStyle *pStyle = _input->textView.typingAttributes[NSParagraphStyleAttributeName]; return [self styleCondition:pStyle :NSMakeRange(0, 0)]; } NSRange paragraphRange = NSMakeRange(0, 0); - NSRange editorRange = NSMakeRange(0, _editor->textView.textStorage.length); - NSParagraphStyle *paragraph = [_editor->textView.textStorage + NSRange inputRange = NSMakeRange(0, _input->textView.textStorage.length); + NSParagraphStyle *paragraph = [_input->textView.textStorage attribute:NSParagraphStyleAttributeName atIndex:searchLocation longestEffectiveRange: ¶graphRange - inRange:editorRange + inRange:inputRange ]; return [self styleCondition:paragraph :NSMakeRange(0, 0)]; @@ -207,7 +207,7 @@ - (BOOL)detectStyle:(NSRange)range { } - (BOOL)anyOccurence:(NSRange)range { - return [OccurenceUtils any:NSParagraphStyleAttributeName withEditor:_editor inRange:range + return [OccurenceUtils any:NSParagraphStyleAttributeName withInput:_input inRange:range withCondition:^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } @@ -215,7 +215,7 @@ - (BOOL)anyOccurence:(NSRange)range { } - (NSArray *_Nullable)findAllOccurences:(NSRange)range { - return [OccurenceUtils all:NSParagraphStyleAttributeName withEditor:_editor inRange:range + return [OccurenceUtils all:NSParagraphStyleAttributeName withInput:_input inRange:range withCondition:^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } diff --git a/ios/styles/StrikethroughStyle.mm b/ios/styles/StrikethroughStyle.mm index 0a824acc0..6a6088da8 100644 --- a/ios/styles/StrikethroughStyle.mm +++ b/ios/styles/StrikethroughStyle.mm @@ -1,16 +1,16 @@ #import "StyleHeaders.h" -#import "ReactNativeRichTextEditorView.h" +#import "EnrichedTextInputView.h" #import "OccurenceUtils.h" @implementation StrikethroughStyle { - ReactNativeRichTextEditorView *_editor; + EnrichedTextInputView *_input; } + (StyleType)getStyleType { return Strikethrough; } -- (instancetype)initWithEditor:(id)editor { +- (instancetype)initWithInput:(id)input { self = [super init]; - _editor = (ReactNativeRichTextEditorView *) editor; + _input = (EnrichedTextInputView *)input; return self; } @@ -24,23 +24,23 @@ - (void)applyStyle:(NSRange)range { } - (void)addAttributes:(NSRange)range { - [_editor->textView.textStorage addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlineStyleSingle) range:range]; + [_input->textView.textStorage addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlineStyleSingle) range:range]; } - (void)addTypingAttributes { - NSMutableDictionary *newTypingAttrs = [_editor->textView.typingAttributes mutableCopy]; + NSMutableDictionary *newTypingAttrs = [_input->textView.typingAttributes mutableCopy]; newTypingAttrs[NSStrikethroughStyleAttributeName] = @(NSUnderlineStyleSingle); - _editor->textView.typingAttributes = newTypingAttrs; + _input->textView.typingAttributes = newTypingAttrs; } - (void)removeAttributes:(NSRange)range { - [_editor->textView.textStorage removeAttribute:NSStrikethroughStyleAttributeName range:range]; + [_input->textView.textStorage removeAttribute:NSStrikethroughStyleAttributeName range:range]; } - (void)removeTypingAttributes { - NSMutableDictionary *newTypingAttrs = [_editor->textView.typingAttributes mutableCopy]; + NSMutableDictionary *newTypingAttrs = [_input->textView.typingAttributes mutableCopy]; [newTypingAttrs removeObjectForKey: NSStrikethroughStyleAttributeName]; - _editor->textView.typingAttributes = newTypingAttrs; + _input->textView.typingAttributes = newTypingAttrs; } - (BOOL)styleCondition:(id _Nullable)value :(NSRange)range { @@ -50,19 +50,19 @@ - (BOOL)styleCondition:(id _Nullable)value :(NSRange)range { - (BOOL)detectStyle:(NSRange)range { if(range.length >= 1) { - return [OccurenceUtils detect:NSStrikethroughStyleAttributeName withEditor:_editor inRange:range + return [OccurenceUtils detect:NSStrikethroughStyleAttributeName withInput:_input inRange:range withCondition: ^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } ]; } else { - NSNumber *currenStrikethroughAttr = (NSNumber *)_editor->textView.typingAttributes[NSStrikethroughStyleAttributeName]; + NSNumber *currenStrikethroughAttr = (NSNumber *)_input->textView.typingAttributes[NSStrikethroughStyleAttributeName]; return currenStrikethroughAttr != nullptr; } } - (BOOL)anyOccurence:(NSRange)range { - return [OccurenceUtils any:NSStrikethroughStyleAttributeName withEditor:_editor inRange:range + return [OccurenceUtils any:NSStrikethroughStyleAttributeName withInput:_input inRange:range withCondition:^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } @@ -70,7 +70,7 @@ - (BOOL)anyOccurence:(NSRange)range { } - (NSArray *_Nullable)findAllOccurences:(NSRange)range { - return [OccurenceUtils all:NSStrikethroughStyleAttributeName withEditor:_editor inRange:range + return [OccurenceUtils all:NSStrikethroughStyleAttributeName withInput:_input inRange:range withCondition:^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } diff --git a/ios/styles/UnderlineStyle.mm b/ios/styles/UnderlineStyle.mm index e8bfd7c25..d602b73c7 100644 --- a/ios/styles/UnderlineStyle.mm +++ b/ios/styles/UnderlineStyle.mm @@ -1,16 +1,16 @@ #import "StyleHeaders.h" -#import "ReactNativeRichTextEditorView.h" +#import "EnrichedTextInputView.h" #import "OccurenceUtils.h" @implementation UnderlineStyle { - ReactNativeRichTextEditorView *_editor; + EnrichedTextInputView *_input; } + (StyleType)getStyleType { return Underline; } -- (instancetype)initWithEditor:(id)editor { +- (instancetype)initWithInput:(id)input { self = [super init]; - _editor = (ReactNativeRichTextEditorView *) editor; + _input = (EnrichedTextInputView *)input; return self; } @@ -24,29 +24,29 @@ - (void)applyStyle:(NSRange)range { } - (void)addAttributes:(NSRange)range { - [_editor->textView.textStorage addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:range]; + [_input->textView.textStorage addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:range]; } - (void)addTypingAttributes { - NSMutableDictionary *newTypingAttrs = [_editor->textView.typingAttributes mutableCopy]; + NSMutableDictionary *newTypingAttrs = [_input->textView.typingAttributes mutableCopy]; newTypingAttrs[NSUnderlineStyleAttributeName] = @(NSUnderlineStyleSingle); - _editor->textView.typingAttributes = newTypingAttrs; + _input->textView.typingAttributes = newTypingAttrs; } - (void)removeAttributes:(NSRange)range { - [_editor->textView.textStorage removeAttribute:NSUnderlineStyleAttributeName range:range]; + [_input->textView.textStorage removeAttribute:NSUnderlineStyleAttributeName range:range]; } - (void)removeTypingAttributes { - NSMutableDictionary *newTypingAttrs = [_editor->textView.typingAttributes mutableCopy]; + NSMutableDictionary *newTypingAttrs = [_input->textView.typingAttributes mutableCopy]; [newTypingAttrs removeObjectForKey: NSUnderlineStyleAttributeName]; - _editor->textView.typingAttributes = newTypingAttrs; + _input->textView.typingAttributes = newTypingAttrs; } - (BOOL)underlinedLinkConflictsInRange:(NSRange)range { BOOL conflicted = NO; - if([_editor->config linkDecorationLine] == DecorationUnderline) { - LinkStyle *linkStyle = _editor->stylesDict[@([LinkStyle getStyleType])]; + if([_input->config linkDecorationLine] == DecorationUnderline) { + LinkStyle *linkStyle = _input->stylesDict[@([LinkStyle getStyleType])]; conflicted = range.length > 0 ? [linkStyle anyOccurence:range] : [linkStyle detectStyle:range]; @@ -56,17 +56,17 @@ - (BOOL)underlinedLinkConflictsInRange:(NSRange)range { - (BOOL)underlinedMentionConflictsInRange:(NSRange)range { BOOL conflicted = NO; - MentionStyle *mentionStyle = _editor->stylesDict[@([MentionStyle getStyleType])]; + MentionStyle *mentionStyle = _input->stylesDict[@([MentionStyle getStyleType])]; if(range.length == 0) { if([mentionStyle detectStyle:range]) { MentionParams *params = [mentionStyle getMentionParamsAt:range.location]; - conflicted = [_editor->config mentionStylePropsForIndicator:params.indicator].decorationLine == DecorationUnderline; + conflicted = [_input->config mentionStylePropsForIndicator:params.indicator].decorationLine == DecorationUnderline; } } else { NSArray *occurences = [mentionStyle findAllOccurences:range]; for(StylePair *pair in occurences) { MentionParams *params = [mentionStyle getMentionParamsAt:[pair.rangeValue rangeValue].location]; - if([_editor->config mentionStylePropsForIndicator:params.indicator].decorationLine == DecorationUnderline) { + if([_input->config mentionStylePropsForIndicator:params.indicator].decorationLine == DecorationUnderline) { conflicted = YES; break; } @@ -82,19 +82,19 @@ - (BOOL)styleCondition:(id _Nullable)value :(NSRange)range { - (BOOL)detectStyle:(NSRange)range { if(range.length >= 1) { - return [OccurenceUtils detect:NSUnderlineStyleAttributeName withEditor:_editor inRange:range + return [OccurenceUtils detect:NSUnderlineStyleAttributeName withInput:_input inRange:range withCondition: ^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } ]; } else { - NSNumber *currentUnderlineAttr = (NSNumber *)_editor->textView.typingAttributes[NSUnderlineStyleAttributeName]; + NSNumber *currentUnderlineAttr = (NSNumber *)_input->textView.typingAttributes[NSUnderlineStyleAttributeName]; return [self styleCondition:currentUnderlineAttr :range]; } } - (BOOL)anyOccurence:(NSRange)range { - return [OccurenceUtils any:NSUnderlineStyleAttributeName withEditor:_editor inRange:range + return [OccurenceUtils any:NSUnderlineStyleAttributeName withInput:_input inRange:range withCondition:^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } @@ -102,7 +102,7 @@ - (BOOL)anyOccurence:(NSRange)range { } - (NSArray *_Nullable)findAllOccurences:(NSRange)range { - return [OccurenceUtils all:NSUnderlineStyleAttributeName withEditor:_editor inRange:range + return [OccurenceUtils all:NSUnderlineStyleAttributeName withInput:_input inRange:range withCondition:^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } diff --git a/ios/styles/UnorderedListStyle.mm b/ios/styles/UnorderedListStyle.mm index 173727a33..bab837362 100644 --- a/ios/styles/UnorderedListStyle.mm +++ b/ios/styles/UnorderedListStyle.mm @@ -1,12 +1,12 @@ #import "StyleHeaders.h" -#import "ReactNativeRichTextEditorView.h" +#import "EnrichedTextInputView.h" #import "FontExtension.h" #import "OccurenceUtils.h" #import "ParagraphsUtils.h" #import "TextInsertionUtils.h" @implementation UnorderedListStyle { - ReactNativeRichTextEditorView *_editor; + EnrichedTextInputView *_input; } + (StyleType)getStyleType { return UnorderedList; } @@ -14,12 +14,12 @@ + (StyleType)getStyleType { return UnorderedList; } - (CGFloat)getHeadIndent { // lists are drawn manually // margin before bullet + gap between bullet and paragraph - return [_editor->config unorderedListMarginLeft] + [_editor->config unorderedListGapWidth]; + return [_input->config unorderedListMarginLeft] + [_input->config unorderedListGapWidth]; } -- (instancetype)initWithEditor:(id)editor { +- (instancetype)initWithInput:(id)input { self = [super init]; - _editor = (ReactNativeRichTextEditorView *) editor; + _input = (EnrichedTextInputView *)input; return self; } @@ -35,14 +35,14 @@ - (void)applyStyle:(NSRange)range { // we assume correct paragraph range is already given - (void)addAttributes:(NSRange)range { NSTextList *bullet = [[NSTextList alloc] initWithMarkerFormat:NSTextListMarkerDisc options:0]; - NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:_editor->textView range:range]; + NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView range:range]; // if we fill empty lines with zero width spaces, we need to offset later ranges NSInteger offset = 0; // needed for range adjustments - NSRange preModificationRange = _editor->textView.selectedRange; + NSRange preModificationRange = _input->textView.selectedRange; // let's not emit some weird selection changes or text/html changes - _editor->blockEmitting = YES; + _input->blockEmitting = YES; for(NSValue *value in paragraphs) { // take previous offsets into consideration @@ -51,93 +51,93 @@ - (void)addAttributes:(NSRange)range { // length 0 with first line, length 1 and newline with some empty lines in the middle if(fixedRange.length == 0 || (fixedRange.length == 1 && - [[NSCharacterSet newlineCharacterSet] characterIsMember: [_editor->textView.textStorage.string characterAtIndex:fixedRange.location]]) + [[NSCharacterSet newlineCharacterSet] characterIsMember: [_input->textView.textStorage.string characterAtIndex:fixedRange.location]]) ) { - [TextInsertionUtils insertText:@"\u200B" at:fixedRange.location additionalAttributes:nullptr editor:_editor withSelection:NO]; + [TextInsertionUtils insertText:@"\u200B" at:fixedRange.location additionalAttributes:nullptr input:_input withSelection:NO]; fixedRange = NSMakeRange(fixedRange.location, fixedRange.length + 1); offset += 1; } - [_editor->textView.textStorage enumerateAttribute:NSParagraphStyleAttributeName inRange:fixedRange options:0 + [_input->textView.textStorage enumerateAttribute:NSParagraphStyleAttributeName inRange:fixedRange options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { NSMutableParagraphStyle *pStyle = [(NSParagraphStyle *)value mutableCopy]; pStyle.textLists = @[bullet]; pStyle.headIndent = [self getHeadIndent]; pStyle.firstLineHeadIndent = [self getHeadIndent]; - [_editor->textView.textStorage addAttribute:NSParagraphStyleAttributeName value:pStyle range:range]; + [_input->textView.textStorage addAttribute:NSParagraphStyleAttributeName value:pStyle range:range]; } ]; } // back to emitting - _editor->blockEmitting = NO; + _input->blockEmitting = NO; if(preModificationRange.length == 0) { // fix selection if only one line was possibly made a list and filled with a space - _editor->textView.selectedRange = preModificationRange; + _input->textView.selectedRange = preModificationRange; } else { // in other cases, fix the selection with newly made offsets - _editor->textView.selectedRange = NSMakeRange(preModificationRange.location, preModificationRange.length + offset); + _input->textView.selectedRange = NSMakeRange(preModificationRange.location, preModificationRange.length + offset); } // also add typing attributes - NSMutableDictionary *typingAttrs = [_editor->textView.typingAttributes mutableCopy]; + NSMutableDictionary *typingAttrs = [_input->textView.typingAttributes mutableCopy]; NSMutableParagraphStyle *pStyle = [typingAttrs[NSParagraphStyleAttributeName] mutableCopy]; pStyle.textLists = @[bullet]; pStyle.headIndent = [self getHeadIndent]; pStyle.firstLineHeadIndent = [self getHeadIndent]; typingAttrs[NSParagraphStyleAttributeName] = pStyle; - _editor->textView.typingAttributes = typingAttrs; + _input->textView.typingAttributes = typingAttrs; } // does pretty much the same as normal addAttributes, just need to get the range - (void)addTypingAttributes { - [self addAttributes:_editor->textView.selectedRange]; + [self addAttributes:_input->textView.selectedRange]; } - (void)removeAttributes:(NSRange)range { - NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:_editor->textView range:range]; + NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView range:range]; - [_editor->textView.textStorage beginEditing]; + [_input->textView.textStorage beginEditing]; for(NSValue *value in paragraphs) { NSRange range = [value rangeValue]; - [_editor->textView.textStorage enumerateAttribute:NSParagraphStyleAttributeName inRange:range options:0 + [_input->textView.textStorage enumerateAttribute:NSParagraphStyleAttributeName inRange:range options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { NSMutableParagraphStyle *pStyle = [(NSParagraphStyle *)value mutableCopy]; pStyle.textLists = @[]; pStyle.headIndent = 0; pStyle.firstLineHeadIndent = 0; - [_editor->textView.textStorage addAttribute:NSParagraphStyleAttributeName value:pStyle range:range]; + [_input->textView.textStorage addAttribute:NSParagraphStyleAttributeName value:pStyle range:range]; } ]; } - [_editor->textView.textStorage endEditing]; + [_input->textView.textStorage endEditing]; // also remove typing attributes - NSMutableDictionary *typingAttrs = [_editor->textView.typingAttributes mutableCopy]; + NSMutableDictionary *typingAttrs = [_input->textView.typingAttributes mutableCopy]; NSMutableParagraphStyle *pStyle = [typingAttrs[NSParagraphStyleAttributeName] mutableCopy]; pStyle.textLists = @[]; pStyle.headIndent = 0; pStyle.firstLineHeadIndent = 0; typingAttrs[NSParagraphStyleAttributeName] = pStyle; - _editor->textView.typingAttributes = typingAttrs; + _input->textView.typingAttributes = typingAttrs; } // needed for the sake of style conflicts, needs to do exactly the same as removeAttribtues - (void)removeTypingAttributes { - [self removeAttributes:_editor->textView.selectedRange]; + [self removeAttributes:_input->textView.selectedRange]; } // removing first list point by backspacing doesn't remove typing attributes because it doesn't run textViewDidChange // so we try guessing that a point should be deleted here - (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text { - if([self detectStyle:_editor->textView.selectedRange] && - NSEqualRanges(_editor->textView.selectedRange, NSMakeRange(0, 0)) && + if([self detectStyle:_input->textView.selectedRange] && + NSEqualRanges(_input->textView.selectedRange, NSMakeRange(0, 0)) && [text isEqualToString:@""] ) { - NSRange paragraphRange = [_editor->textView.textStorage.string paragraphRangeForRange:_editor->textView.selectedRange]; + NSRange paragraphRange = [_input->textView.textStorage.string paragraphRangeForRange:_input->textView.selectedRange]; [self removeAttributes:paragraphRange]; return YES; } @@ -145,24 +145,24 @@ - (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text { } - (BOOL)tryHandlingListShorcutInRange:(NSRange)range replacementText:(NSString *)text { - NSRange paragraphRange = [_editor->textView.textStorage.string paragraphRangeForRange:range]; + NSRange paragraphRange = [_input->textView.textStorage.string paragraphRangeForRange:range]; // space was added - check if we are both at the paragraph beginning + 1 character (which we want to be a dash) if([text isEqualToString:@" "] && range.location - 1 == paragraphRange.location) { - unichar charBefore = [_editor->textView.textStorage.string characterAtIndex:range.location - 1]; + unichar charBefore = [_input->textView.textStorage.string characterAtIndex:range.location - 1]; if(charBefore == '-') { // we got a match - add a list if possible - if([_editor handleStyleBlocksAndConflicts:[[self class] getStyleType] range:paragraphRange]) { + if([_input handleStyleBlocksAndConflicts:[[self class] getStyleType] range:paragraphRange]) { // don't emit some html updates during the replacing - BOOL prevEmitHtml = _editor->emitHtml; + BOOL prevEmitHtml = _input->emitHtml; if(prevEmitHtml) { - _editor->emitHtml = NO; + _input->emitHtml = NO; } // remove the dash - [TextInsertionUtils replaceText:@"" at:NSMakeRange(paragraphRange.location, 1) additionalAttributes:nullptr editor:_editor withSelection:YES]; + [TextInsertionUtils replaceText:@"" at:NSMakeRange(paragraphRange.location, 1) additionalAttributes:nullptr input:_input withSelection:YES]; if(prevEmitHtml) { - _editor->emitHtml = YES; + _input->emitHtml = YES; } // add attributes on the dashless paragraph @@ -181,25 +181,25 @@ - (BOOL)styleCondition:(id _Nullable)value :(NSRange)range { - (BOOL)detectStyle:(NSRange)range { if(range.length >= 1) { - return [OccurenceUtils detect:NSParagraphStyleAttributeName withEditor:_editor inRange:range + return [OccurenceUtils detect:NSParagraphStyleAttributeName withInput:_input inRange:range withCondition: ^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } ]; } else { NSInteger searchLocation = range.location; - if(searchLocation == _editor->textView.textStorage.length) { - NSParagraphStyle *pStyle = _editor->textView.typingAttributes[NSParagraphStyleAttributeName]; + if(searchLocation == _input->textView.textStorage.length) { + NSParagraphStyle *pStyle = _input->textView.typingAttributes[NSParagraphStyleAttributeName]; return [self styleCondition:pStyle :NSMakeRange(0, 0)]; } NSRange paragraphRange = NSMakeRange(0, 0); - NSRange editorRange = NSMakeRange(0, _editor->textView.textStorage.length); - NSParagraphStyle *paragraph = [_editor->textView.textStorage + NSRange inputRange = NSMakeRange(0, _input->textView.textStorage.length); + NSParagraphStyle *paragraph = [_input->textView.textStorage attribute:NSParagraphStyleAttributeName atIndex:searchLocation longestEffectiveRange: ¶graphRange - inRange:editorRange + inRange:inputRange ]; return [self styleCondition:paragraph :NSMakeRange(0, 0)]; @@ -207,7 +207,7 @@ - (BOOL)detectStyle:(NSRange)range { } - (BOOL)anyOccurence:(NSRange)range { - return [OccurenceUtils any:NSParagraphStyleAttributeName withEditor:_editor inRange:range + return [OccurenceUtils any:NSParagraphStyleAttributeName withInput:_input inRange:range withCondition:^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } @@ -215,7 +215,7 @@ - (BOOL)anyOccurence:(NSRange)range { } - (NSArray *_Nullable)findAllOccurences:(NSRange)range { - return [OccurenceUtils all:NSParagraphStyleAttributeName withEditor:_editor inRange:range + return [OccurenceUtils all:NSParagraphStyleAttributeName withInput:_input inRange:range withCondition:^BOOL(id _Nullable value, NSRange range) { return [self styleCondition:value :range]; } diff --git a/ios/utils/BaseStyleProtocol.h b/ios/utils/BaseStyleProtocol.h index b60d4fab8..82e59886d 100644 --- a/ios/utils/BaseStyleProtocol.h +++ b/ios/utils/BaseStyleProtocol.h @@ -4,7 +4,7 @@ @protocol BaseStyleProtocol + (StyleType)getStyleType; -- (instancetype _Nonnull)initWithEditor:(id _Nonnull)editor; +- (instancetype _Nonnull)initWithInput:(id _Nonnull)input; - (void)applyStyle:(NSRange)range; - (void)addAttributes:(NSRange)range; - (void)removeAttributes:(NSRange)range; diff --git a/ios/utils/FontExtension.h b/ios/utils/FontExtension.h index c53cfdc14..0b0ab84cc 100644 --- a/ios/utils/FontExtension.h +++ b/ios/utils/FontExtension.h @@ -1,5 +1,4 @@ #import -#import #pragma once @interface UIFont (FontExtension) diff --git a/ios/utils/FontExtension.mm b/ios/utils/FontExtension.mm index 345997d3a..3a664e586 100644 --- a/ios/utils/FontExtension.mm +++ b/ios/utils/FontExtension.mm @@ -16,7 +16,7 @@ - (UIFont *)setBold { if(fontDescriptor != nullptr) { return [UIFont fontWithDescriptor:fontDescriptor size:0]; } else { - RCTLogWarn(@"[RichTextEditor]: Couldn't apply bold trait to the font."); + RCTLogWarn(@"[EnrichedTextInput]: Couldn't apply bold trait to the font."); return self; } } @@ -30,7 +30,7 @@ - (UIFont *)removeBold { if(fontDescriptor != nullptr) { return [UIFont fontWithDescriptor:fontDescriptor size:0]; } else { - RCTLogWarn(@"[RichTextEditor]: Couldn't remove bold trait from the font."); + RCTLogWarn(@"[EnrichedTextInput]: Couldn't remove bold trait from the font."); return self; } } @@ -48,7 +48,7 @@ - (UIFont *)setItalic { if(fontDescriptor != nullptr) { return [UIFont fontWithDescriptor:fontDescriptor size:0]; } else { - RCTLogWarn(@"[RichTextEditor]: Couldn't apply italic trait to the font."); + RCTLogWarn(@"[EnrichedTextInput]: Couldn't apply italic trait to the font."); return self; } } @@ -62,7 +62,7 @@ - (UIFont *)removeItalic { if(fontDescriptor != nullptr) { return [UIFont fontWithDescriptor:fontDescriptor size:0]; } else { - RCTLogWarn(@"[RichTextEditor]: Couldn't remove italic trait from the font."); + RCTLogWarn(@"[EnrichedTextInput]: Couldn't remove italic trait from the font."); return self; } } @@ -83,7 +83,7 @@ - (UIFont *)setSize:(CGFloat)size { if(newFontDescriptor != nullptr) { return [UIFont fontWithDescriptor:newFontDescriptor size:0]; } else { - RCTLogWarn(@"[RichTextEditor]: Couldn't apply heading style to the font."); + RCTLogWarn(@"[EnrichedTextInput]: Couldn't apply heading style to the font."); return self; } } diff --git a/ios/utils/LayoutManagerExtension.h b/ios/utils/LayoutManagerExtension.h index 516554eca..6f54c6c9b 100644 --- a/ios/utils/LayoutManagerExtension.h +++ b/ios/utils/LayoutManagerExtension.h @@ -2,5 +2,5 @@ #import @interface NSLayoutManager (LayoutManagerExtension) -@property (nonatomic, weak) id editor; +@property (nonatomic, weak) id input; @end diff --git a/ios/utils/LayoutManagerExtension.mm b/ios/utils/LayoutManagerExtension.mm index 1f07fc570..26a9cbcdd 100644 --- a/ios/utils/LayoutManagerExtension.mm +++ b/ios/utils/LayoutManagerExtension.mm @@ -1,21 +1,21 @@ #import "LayoutManagerExtension.h" #import -#import "ReactNativeRichTextEditorView.h" +#import "EnrichedTextInputView.h" #import "StyleHeaders.h" #import "ParagraphsUtils.h" @implementation NSLayoutManager (LayoutManagerExtension) -static void const *kEditorKey = &kEditorKey; +static void const *kInputKey = &kInputKey; -- (id)editor { - return objc_getAssociatedObject(self, kEditorKey); +- (id)input { + return objc_getAssociatedObject(self, kInputKey); } -- (void)setEditor:(id)value { +- (void)setInput:(id)value { objc_setAssociatedObject( self, - kEditorKey, + kInputKey, value, OBJC_ASSOCIATION_RETAIN_NONATOMIC ); @@ -49,19 +49,19 @@ + (void)load { - (void)my_drawBackgroundForGlyphRange:(NSRange)glyphRange atPoint:(CGPoint)origin { [self my_drawBackgroundForGlyphRange:glyphRange atPoint:origin]; - ReactNativeRichTextEditorView *typedEditor = (ReactNativeRichTextEditorView *)self.editor; - if(typedEditor == nullptr) { return; } + EnrichedTextInputView *typedInput = (EnrichedTextInputView *)self.input; + if(typedInput == nullptr) { return; } - BlockQuoteStyle *bqStyle = typedEditor->stylesDict[@([BlockQuoteStyle getStyleType])]; + BlockQuoteStyle *bqStyle = typedInput->stylesDict[@([BlockQuoteStyle getStyleType])]; if(bqStyle == nullptr) { return; } - NSRange editorRange = NSMakeRange(0, typedEditor->textView.textStorage.length); + NSRange inputRange = NSMakeRange(0, typedInput->textView.textStorage.length); // it isn't the most performant but we have to check for all the blockquotes each time and redraw them - NSArray *allBlockquotes = [bqStyle findAllOccurences:editorRange]; + NSArray *allBlockquotes = [bqStyle findAllOccurences:inputRange]; for(StylePair *pair in allBlockquotes) { - NSRange paragraphRange = [typedEditor->textView.textStorage.string paragraphRangeForRange:[pair.rangeValue rangeValue]]; + NSRange paragraphRange = [typedInput->textView.textStorage.string paragraphRangeForRange:[pair.rangeValue rangeValue]]; NSRange paragraphGlyphRange = [self glyphRangeForCharacterRange:paragraphRange actualCharacterRange:nullptr]; [self enumerateLineFragmentsForGlyphRange:paragraphGlyphRange usingBlock:^(CGRect rect, CGRect usedRect, NSTextContainer * _Nonnull textContainer, NSRange glyphRange, BOOL * _Nonnull stop) { @@ -69,56 +69,56 @@ - (void)my_drawBackgroundForGlyphRange:(NSRange)glyphRange atPoint:(CGPoint)orig CGFloat paddingTop = origin.y; CGFloat x = paddingLeft; CGFloat y = paddingTop + rect.origin.y; - CGFloat width = [typedEditor->config blockquoteBorderWidth]; + CGFloat width = [typedInput->config blockquoteBorderWidth]; CGFloat height = rect.size.height; CGRect lineRect = CGRectMake(x, y, width, height); - [[typedEditor->config blockquoteBorderColor] setFill]; + [[typedInput->config blockquoteBorderColor] setFill]; UIRectFill(lineRect); } ]; } - UnorderedListStyle *ulStyle = typedEditor->stylesDict[@([UnorderedListStyle getStyleType])]; - OrderedListStyle *olStyle = typedEditor->stylesDict[@([OrderedListStyle getStyleType])]; + UnorderedListStyle *ulStyle = typedInput->stylesDict[@([UnorderedListStyle getStyleType])]; + OrderedListStyle *olStyle = typedInput->stylesDict[@([OrderedListStyle getStyleType])]; if(ulStyle == nullptr || olStyle == nullptr) { return; } // also not the most performant but we redraw all the lists NSMutableArray *allLists = [[NSMutableArray alloc] init]; - [allLists addObjectsFromArray:[ulStyle findAllOccurences:editorRange]]; - [allLists addObjectsFromArray:[olStyle findAllOccurences:editorRange]]; + [allLists addObjectsFromArray:[ulStyle findAllOccurences:inputRange]]; + [allLists addObjectsFromArray:[olStyle findAllOccurences:inputRange]]; for(StylePair *pair in allLists) { NSParagraphStyle *pStyle = (NSParagraphStyle *)pair.styleValue; NSDictionary *markerAttributes = @{ - NSFontAttributeName: [typedEditor->config orderedListMarkerFont], - NSForegroundColorAttributeName: [typedEditor->config orderedListMarkerColor] + NSFontAttributeName: [typedInput->config orderedListMarkerFont], + NSForegroundColorAttributeName: [typedInput->config orderedListMarkerColor] }; - NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:typedEditor->textView range:[pair.rangeValue rangeValue]]; + NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:typedInput->textView range:[pair.rangeValue rangeValue]]; for(NSValue *paragraph in paragraphs) { NSRange paragraphGlyphRange = [self glyphRangeForCharacterRange:[paragraph rangeValue] actualCharacterRange:nullptr]; [self enumerateLineFragmentsForGlyphRange:paragraphGlyphRange usingBlock:^(CGRect rect, CGRect usedRect, NSTextContainer *container, NSRange lineGlyphRange, BOOL *stop) { - NSString *marker = [self markerForList:pStyle.textLists.firstObject charIndex:[self characterIndexForGlyphAtIndex:lineGlyphRange.location] editor:typedEditor]; + NSString *marker = [self markerForList:pStyle.textLists.firstObject charIndex:[self characterIndexForGlyphAtIndex:lineGlyphRange.location] input:typedInput]; if(pStyle.textLists.firstObject.markerFormat == NSTextListMarkerDecimal) { - CGFloat gapWidth = [typedEditor->config orderedListGapWidth]; + CGFloat gapWidth = [typedInput->config orderedListGapWidth]; CGFloat markerWidth = [marker sizeWithAttributes:markerAttributes].width; CGFloat markerX = usedRect.origin.x - gapWidth - markerWidth/2; [marker drawAtPoint:CGPointMake(markerX, usedRect.origin.y + origin.y) withAttributes:markerAttributes]; } else { - CGFloat gapWidth = [typedEditor->config unorderedListGapWidth]; - CGFloat bulletSize = [typedEditor->config unorderedListBulletSize]; + CGFloat gapWidth = [typedInput->config unorderedListGapWidth]; + CGFloat bulletSize = [typedInput->config unorderedListBulletSize]; CGFloat bulletX = usedRect.origin.x - gapWidth - bulletSize/2; CGFloat centerY = CGRectGetMidY(usedRect); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); { - [[typedEditor->config unorderedListBulletColor] setFill]; + [[typedInput->config unorderedListBulletColor] setFill]; CGContextAddArc(context, bulletX, centerY, bulletSize/2, 0, 2 * M_PI, YES); CGContextFillPath(context); } @@ -132,14 +132,14 @@ - (void)my_drawBackgroundForGlyphRange:(NSRange)glyphRange atPoint:(CGPoint)orig } } -- (NSString *)markerForList:(NSTextList *)list charIndex:(NSUInteger)index editor:(ReactNativeRichTextEditorView *)editor { +- (NSString *)markerForList:(NSTextList *)list charIndex:(NSUInteger)index input:(EnrichedTextInputView *)input { if(list.markerFormat == NSTextListMarkerDecimal) { - NSString *fullText = editor->textView.textStorage.string; + NSString *fullText = input->textView.textStorage.string; NSInteger itemNumber = 1; NSRange currentParagraph = [fullText paragraphRangeForRange:NSMakeRange(index, 0)]; if(currentParagraph.location > 0) { - OrderedListStyle *olStyle = editor->stylesDict[@([OrderedListStyle getStyleType])]; + OrderedListStyle *olStyle = input->stylesDict[@([OrderedListStyle getStyleType])]; NSInteger prevParagraphsCount = 0; NSInteger recentParagraphLocation = [fullText paragraphRangeForRange:NSMakeRange(currentParagraph.location - 1, 0)].location; diff --git a/ios/utils/MentionStyleProps.mm b/ios/utils/MentionStyleProps.mm index 11707f063..da35fc2fa 100644 --- a/ios/utils/MentionStyleProps.mm +++ b/ios/utils/MentionStyleProps.mm @@ -1,7 +1,6 @@ #import "MentionStyleProps.h" #import #import "StringExtension.h" -#import "ReactNativeRichTextEditorView.h" @implementation MentionStyleProps diff --git a/ios/utils/OccurenceUtils.h b/ios/utils/OccurenceUtils.h index 7277ef403..dc6b501cd 100644 --- a/ios/utils/OccurenceUtils.h +++ b/ios/utils/OccurenceUtils.h @@ -1,37 +1,37 @@ #pragma once #import "StylePair.h" -#import "ReactNativeRichTextEditorView.h" +#import "EnrichedTextInputView.h" @interface OccurenceUtils : NSObject + (BOOL)detect :(NSAttributedStringKey _Nonnull)key - withEditor:(ReactNativeRichTextEditorView* _Nonnull)editor + withInput:(EnrichedTextInputView* _Nonnull)input inRange:(NSRange)range withCondition:(BOOL (NS_NOESCAPE ^_Nonnull)(id _Nullable value, NSRange range))condition; + (BOOL)detectMultiple :(NSArray *_Nonnull)keys - withEditor:(ReactNativeRichTextEditorView* _Nonnull)editor + withInput:(EnrichedTextInputView* _Nonnull)input inRange:(NSRange)range withCondition:(BOOL (NS_NOESCAPE ^_Nonnull)(id _Nullable value, NSRange range))condition; + (BOOL)any :(NSAttributedStringKey _Nonnull)key - withEditor:(ReactNativeRichTextEditorView* _Nonnull)editor + withInput:(EnrichedTextInputView* _Nonnull)input inRange:(NSRange)range withCondition:(BOOL (NS_NOESCAPE ^_Nonnull)(id _Nullable value, NSRange range))condition; + (BOOL)anyMultiple :(NSArray *_Nonnull)keys - withEditor:(ReactNativeRichTextEditorView* _Nonnull)editor + withInput:(EnrichedTextInputView* _Nonnull)input inRange:(NSRange)range withCondition:(BOOL (NS_NOESCAPE ^_Nonnull)(id _Nullable value, NSRange range))condition; + (NSArray *_Nullable)all :(NSAttributedStringKey _Nonnull)key - withEditor:(ReactNativeRichTextEditorView* _Nonnull)editor + withInput:(EnrichedTextInputView* _Nonnull)input inRange:(NSRange)range withCondition:(BOOL (NS_NOESCAPE ^_Nonnull)(id _Nullable value, NSRange range))condition; + (NSArray *_Nullable)allMultiple :(NSArray *_Nonnull)keys - withEditor:(ReactNativeRichTextEditorView* _Nonnull)editor + withInput:(EnrichedTextInputView* _Nonnull)input inRange:(NSRange)range withCondition:(BOOL (NS_NOESCAPE ^_Nonnull)(id _Nullable value, NSRange range))condition; @end diff --git a/ios/utils/OccurenceUtils.mm b/ios/utils/OccurenceUtils.mm index c612e851d..6248c735c 100644 --- a/ios/utils/OccurenceUtils.mm +++ b/ios/utils/OccurenceUtils.mm @@ -4,12 +4,12 @@ @implementation OccurenceUtils + (BOOL)detect :(NSAttributedStringKey _Nonnull)key - withEditor:(ReactNativeRichTextEditorView* _Nonnull)editor + withInput:(EnrichedTextInputView* _Nonnull)input inRange:(NSRange)range withCondition:(BOOL (NS_NOESCAPE ^_Nonnull)(id _Nullable value, NSRange range))condition { __block NSInteger totalLength = 0; - [editor->textView.textStorage enumerateAttribute:key inRange:range options:0 usingBlock: + [input->textView.textStorage enumerateAttribute:key inRange:range options:0 usingBlock: ^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { if(condition(value, range)) { totalLength += range.length; @@ -21,13 +21,13 @@ + (BOOL)detect + (BOOL)detectMultiple :(NSArray *_Nonnull)keys - withEditor:(ReactNativeRichTextEditorView* _Nonnull)editor + withInput:(EnrichedTextInputView* _Nonnull)input inRange:(NSRange)range withCondition:(BOOL (NS_NOESCAPE ^_Nonnull)(id _Nullable value, NSRange range))condition { __block NSInteger totalLength = 0; for(NSString* key in keys) { - [editor->textView.textStorage enumerateAttribute:key inRange:range options:0 usingBlock: + [input->textView.textStorage enumerateAttribute:key inRange:range options:0 usingBlock: ^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { if(condition(value, range)) { totalLength += range.length; @@ -40,12 +40,12 @@ + (BOOL)detectMultiple + (BOOL)any :(NSAttributedStringKey _Nonnull)key - withEditor:(ReactNativeRichTextEditorView* _Nonnull)editor + withInput:(EnrichedTextInputView* _Nonnull)input inRange:(NSRange)range withCondition:(BOOL (NS_NOESCAPE ^_Nonnull)(id _Nullable value, NSRange range))condition { __block BOOL found = NO; - [editor->textView.textStorage enumerateAttribute:key inRange:range options:0 usingBlock: + [input->textView.textStorage enumerateAttribute:key inRange:range options:0 usingBlock: ^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { if(condition(value, range)) { found = YES; @@ -58,13 +58,13 @@ + (BOOL)any + (BOOL)anyMultiple :(NSArray *_Nonnull)keys - withEditor:(ReactNativeRichTextEditorView* _Nonnull)editor + withInput:(EnrichedTextInputView* _Nonnull)input inRange:(NSRange)range withCondition:(BOOL (NS_NOESCAPE ^_Nonnull)(id _Nullable value, NSRange range))condition { __block BOOL found = NO; for(NSString *key in keys) { - [editor->textView.textStorage enumerateAttribute:key inRange:range options:0 usingBlock: + [input->textView.textStorage enumerateAttribute:key inRange:range options:0 usingBlock: ^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { if(condition(value, range)) { found = YES; @@ -81,12 +81,12 @@ + (BOOL)anyMultiple + (NSArray *_Nullable)all :(NSAttributedStringKey _Nonnull)key - withEditor:(ReactNativeRichTextEditorView* _Nonnull)editor + withInput:(EnrichedTextInputView* _Nonnull)input inRange:(NSRange)range withCondition:(BOOL (NS_NOESCAPE ^_Nonnull)(id _Nullable value, NSRange range))condition { __block NSMutableArray *occurences = [[NSMutableArray alloc] init]; - [editor->textView.textStorage enumerateAttribute:key inRange:range options:0 usingBlock: + [input->textView.textStorage enumerateAttribute:key inRange:range options:0 usingBlock: ^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { if(condition(value, range)) { StylePair *pair = [[StylePair alloc] init]; @@ -101,13 +101,13 @@ + (BOOL)anyMultiple + (NSArray *_Nullable)allMultiple :(NSArray *_Nonnull)keys - withEditor:(ReactNativeRichTextEditorView* _Nonnull)editor + withInput:(EnrichedTextInputView* _Nonnull)input inRange:(NSRange)range withCondition:(BOOL (NS_NOESCAPE ^_Nonnull)(id _Nullable value, NSRange range))condition { __block NSMutableArray *occurences = [[NSMutableArray alloc] init]; for(NSString *key in keys) { - [editor->textView.textStorage enumerateAttribute:key inRange:range options:0 usingBlock: + [input->textView.textStorage enumerateAttribute:key inRange:range options:0 usingBlock: ^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { if(condition(value, range)) { StylePair *pair = [[StylePair alloc] init]; diff --git a/ios/utils/StyleHeaders.h b/ios/utils/StyleHeaders.h index 90bcb5bd6..9ab71aeb9 100644 --- a/ios/utils/StyleHeaders.h +++ b/ios/utils/StyleHeaders.h @@ -43,7 +43,7 @@ @end @interface HeadingStyleBase : NSObject { - id editor; + id input; } - (CGFloat)getHeadingFontSize; - (BOOL)isHeadingBold; diff --git a/ios/utils/TextInsertionUtils.h b/ios/utils/TextInsertionUtils.h index 538b4b125..2d48ce184 100644 --- a/ios/utils/TextInsertionUtils.h +++ b/ios/utils/TextInsertionUtils.h @@ -1,6 +1,6 @@ #import @interface TextInsertionUtils : NSObject -+ (void)insertText:(NSString*)text at:(NSInteger)index additionalAttributes:(NSDictionary*)additionalAttrs editor:(id)editor withSelection:(BOOL)withSelection; -+ (void)replaceText:(NSString*)text at:(NSRange)range additionalAttributes:(NSDictionary*)additionalAttrs editor:(id)editor withSelection:(BOOL)withSelection;; ++ (void)insertText:(NSString*)text at:(NSInteger)index additionalAttributes:(NSDictionary*)additionalAttrs input:(id)input withSelection:(BOOL)withSelection; ++ (void)replaceText:(NSString*)text at:(NSRange)range additionalAttributes:(NSDictionary*)additionalAttrs input:(id)input withSelection:(BOOL)withSelection;; @end diff --git a/ios/utils/TextInsertionUtils.mm b/ios/utils/TextInsertionUtils.mm index e0b7971df..83b8c7b94 100644 --- a/ios/utils/TextInsertionUtils.mm +++ b/ios/utils/TextInsertionUtils.mm @@ -1,13 +1,13 @@ #import "TextInsertionUtils.h" #import "UIView+React.h" -#import "ReactNativeRichTextEditorView.h" +#import "EnrichedTextInputView.h" @implementation TextInsertionUtils -+ (void)insertText:(NSString*)text at:(NSInteger)index additionalAttributes:(NSDictionary*)additionalAttrs editor:(id)editor withSelection:(BOOL)withSelection { - ReactNativeRichTextEditorView *typedEditor = (ReactNativeRichTextEditorView *)editor; - if(typedEditor == nullptr) { return; } ++ (void)insertText:(NSString*)text at:(NSInteger)index additionalAttributes:(NSDictionary*)additionalAttrs input:(id)input withSelection:(BOOL)withSelection { + EnrichedTextInputView *typedInput = (EnrichedTextInputView *)input; + if(typedInput == nullptr) { return; } - UITextView *textView = typedEditor->textView; + UITextView *textView = typedInput->textView; NSMutableDictionary *copiedAttrs = [textView.typingAttributes mutableCopy]; if(additionalAttrs != nullptr) { @@ -23,14 +23,14 @@ + (void)insertText:(NSString*)text at:(NSInteger)index additionalAttributes:(NSD } textView.selectedRange = NSMakeRange(index + text.length, 0); } - typedEditor->recentlyChangedRange = NSMakeRange(index, text.length); + typedInput->recentlyChangedRange = NSMakeRange(index, text.length); } -+ (void)replaceText:(NSString*)text at:(NSRange)range additionalAttributes:(NSDictionary*)additionalAttrs editor:(id)editor withSelection:(BOOL)withSelection { - ReactNativeRichTextEditorView *typedEditor = (ReactNativeRichTextEditorView *)editor; - if(typedEditor == nullptr) { return; } ++ (void)replaceText:(NSString*)text at:(NSRange)range additionalAttributes:(NSDictionary*)additionalAttrs input:(id)input withSelection:(BOOL)withSelection { + EnrichedTextInputView *typedInput = (EnrichedTextInputView *)input; + if(typedInput == nullptr) { return; } - UITextView *textView = typedEditor->textView; + UITextView *textView = typedInput->textView; [textView.textStorage replaceCharactersInRange:range withString:text]; if(additionalAttrs != nullptr) { @@ -43,6 +43,6 @@ + (void)replaceText:(NSString*)text at:(NSRange)range additionalAttributes:(NSDi } textView.selectedRange = NSMakeRange(range.location + text.length, 0); } - typedEditor->recentlyChangedRange = NSMakeRange(range.location, text.length); + typedInput->recentlyChangedRange = NSMakeRange(range.location, text.length); } @end diff --git a/ios/utils/ZeroWidthSpaceUtils.h b/ios/utils/ZeroWidthSpaceUtils.h index d9bd817b1..27befa38a 100644 --- a/ios/utils/ZeroWidthSpaceUtils.h +++ b/ios/utils/ZeroWidthSpaceUtils.h @@ -2,6 +2,6 @@ #pragma once @interface ZeroWidthSpaceUtils : NSObject -+ (void)handleZeroWidthSpacesInEditor:(id)editor; -+ (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text editor:(id)editor; ++ (void)handleZeroWidthSpacesInInput:(id)input; ++ (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text input:(id)input; @end diff --git a/ios/utils/ZeroWidthSpaceUtils.mm b/ios/utils/ZeroWidthSpaceUtils.mm index 25c4f9c27..04e785989 100644 --- a/ios/utils/ZeroWidthSpaceUtils.mm +++ b/ios/utils/ZeroWidthSpaceUtils.mm @@ -1,35 +1,35 @@ #import "ZeroWidthSpaceUtils.h" -#import "ReactNativeRichTextEditorView.h" +#import "EnrichedTextInputView.h" #import "StyleHeaders.h" #import "TextInsertionUtils.h" #import "UIView+React.h" @implementation ZeroWidthSpaceUtils -+ (void)handleZeroWidthSpacesInEditor:(id)editor { - ReactNativeRichTextEditorView *typedEditor = (ReactNativeRichTextEditorView *)editor; - if(typedEditor == nullptr) { return; } ++ (void)handleZeroWidthSpacesInInput:(id)input { + EnrichedTextInputView *typedInput = (EnrichedTextInputView *)input; + if(typedInput == nullptr) { return; } - [self removeSpacesIfNeededInEditor:typedEditor]; - [self addSpacesIfNeededInEditor:typedEditor]; + [self removeSpacesIfNeededinInput:typedInput]; + [self addSpacesIfNeededinInput:typedInput]; } -+ (void)removeSpacesIfNeededInEditor:(ReactNativeRichTextEditorView *)editor { ++ (void)removeSpacesIfNeededinInput:(EnrichedTextInputView *)input { NSMutableArray *indexesToBeRemoved = [[NSMutableArray alloc] init]; - NSRange preRemoveSelection = editor->textView.selectedRange; + NSRange preRemoveSelection = input->textView.selectedRange; - for(int i = 0; i < editor->textView.textStorage.string.length; i++) { - unichar character = [editor->textView.textStorage.string characterAtIndex:i]; + for(int i = 0; i < input->textView.textStorage.string.length; i++) { + unichar character = [input->textView.textStorage.string characterAtIndex:i]; if(character == 0x200B) { NSRange characterRange = NSMakeRange(i, 1); - NSRange paragraphRange = [editor->textView.textStorage.string paragraphRangeForRange:characterRange]; + NSRange paragraphRange = [input->textView.textStorage.string paragraphRangeForRange:characterRange]; // having paragraph longer than 1 character means someone most likely added something and we probably can remove the space BOOL removeSpace = paragraphRange.length > 1; // exception; 2 characters paragraph with zero width space + newline // here, we still need zero width space to keep the empty list items if(paragraphRange.length == 2 && paragraphRange.location == i && - [[NSCharacterSet newlineCharacterSet] characterIsMember:[editor->textView.textStorage.string characterAtIndex:i+1]] + [[NSCharacterSet newlineCharacterSet] characterIsMember:[input->textView.textStorage.string characterAtIndex:i+1]] ) { removeSpace = NO; } @@ -39,9 +39,9 @@ + (void)removeSpacesIfNeededInEditor:(ReactNativeRichTextEditorView *)editor { continue; } - UnorderedListStyle *ulStyle = editor->stylesDict[@([UnorderedListStyle getStyleType])]; - OrderedListStyle *olStyle = editor->stylesDict[@([OrderedListStyle getStyleType])]; - BlockQuoteStyle *bqStyle = editor->stylesDict[@([BlockQuoteStyle getStyleType])]; + UnorderedListStyle *ulStyle = input->stylesDict[@([UnorderedListStyle getStyleType])]; + OrderedListStyle *olStyle = input->stylesDict[@([OrderedListStyle getStyleType])]; + BlockQuoteStyle *bqStyle = input->stylesDict[@([BlockQuoteStyle getStyleType])]; // zero width spaces with no lists/blockquote styles on them get removed if(![ulStyle detectStyle:characterRange] && ![olStyle detectStyle:characterRange] && ![bqStyle detectStyle:characterRange]) { @@ -55,31 +55,33 @@ + (void)removeSpacesIfNeededInEditor:(ReactNativeRichTextEditorView *)editor { NSInteger postRemoveOffset = 0; for(NSNumber *index in indexesToBeRemoved) { NSRange replaceRange = NSMakeRange([index integerValue] + offset, 1); - [TextInsertionUtils replaceText:@"" at:replaceRange additionalAttributes:nullptr editor:editor withSelection:NO]; + [TextInsertionUtils replaceText:@"" at:replaceRange additionalAttributes:nullptr input:input withSelection:NO]; offset -= 1; if([index integerValue] < preRemoveSelection.location) { postRemoveOffset -= 1; } } - // fix the selection - [editor->textView reactFocus]; - editor->textView.selectedRange = NSMakeRange(preRemoveSelection.location + postRemoveOffset, preRemoveSelection.length); + // fix the selection if needed + if(input->textView.focused) { + [input->textView reactFocus]; + input->textView.selectedRange = NSMakeRange(preRemoveSelection.location + postRemoveOffset, preRemoveSelection.length); + } } -+ (void)addSpacesIfNeededInEditor:(ReactNativeRichTextEditorView *)editor { - UnorderedListStyle *ulStyle = editor->stylesDict[@([UnorderedListStyle getStyleType])]; - OrderedListStyle *olStyle = editor->stylesDict[@([OrderedListStyle getStyleType])]; - BlockQuoteStyle *bqStyle = editor->stylesDict[@([BlockQuoteStyle getStyleType])]; ++ (void)addSpacesIfNeededinInput:(EnrichedTextInputView *)input { + UnorderedListStyle *ulStyle = input->stylesDict[@([UnorderedListStyle getStyleType])]; + OrderedListStyle *olStyle = input->stylesDict[@([OrderedListStyle getStyleType])]; + BlockQuoteStyle *bqStyle = input->stylesDict[@([BlockQuoteStyle getStyleType])]; NSMutableArray *indexesToBeInserted = [[NSMutableArray alloc] init]; - NSRange preAddSelection = editor->textView.selectedRange; + NSRange preAddSelection = input->textView.selectedRange; - for(int i = 0; i < editor->textView.textStorage.string.length; i++) { - unichar character = [editor->textView.textStorage.string characterAtIndex:i]; + for(int i = 0; i < input->textView.textStorage.string.length; i++) { + unichar character = [input->textView.textStorage.string characterAtIndex:i]; if([[NSCharacterSet newlineCharacterSet] characterIsMember:character]) { NSRange characterRange = NSMakeRange(i, 1); - NSRange paragraphRange = [editor->textView.textStorage.string paragraphRangeForRange:characterRange]; + NSRange paragraphRange = [input->textView.textStorage.string paragraphRangeForRange:characterRange]; if(paragraphRange.length == 1) { if([ulStyle detectStyle:characterRange] || [olStyle detectStyle:characterRange] || [bqStyle detectStyle:characterRange]) { @@ -95,7 +97,7 @@ + (void)addSpacesIfNeededInEditor:(ReactNativeRichTextEditorView *)editor { NSInteger postAddOffset = 0; for(NSNumber *index in indexesToBeInserted) { NSRange replaceRange = NSMakeRange([index integerValue] + offset, 1); - [TextInsertionUtils replaceText:@"\u200B\n" at:replaceRange additionalAttributes:nullptr editor:editor withSelection:NO]; + [TextInsertionUtils replaceText:@"\u200B\n" at:replaceRange additionalAttributes:nullptr input:input withSelection:NO]; offset += 1; if([index integerValue] < preAddSelection.location) { postAddOffset += 1; @@ -103,46 +105,48 @@ + (void)addSpacesIfNeededInEditor:(ReactNativeRichTextEditorView *)editor { } // additional check for last index of the input - NSRange lastRange = NSMakeRange(editor->textView.textStorage.string.length, 0); - NSRange lastParagraphRange = [editor->textView.textStorage.string paragraphRangeForRange:lastRange]; + NSRange lastRange = NSMakeRange(input->textView.textStorage.string.length, 0); + NSRange lastParagraphRange = [input->textView.textStorage.string paragraphRangeForRange:lastRange]; if(lastParagraphRange.length == 0 && ([ulStyle detectStyle:lastRange] || [olStyle detectStyle:lastRange] || [bqStyle detectStyle:lastRange])) { - [TextInsertionUtils insertText:@"\u200B" at:lastRange.location additionalAttributes:nullptr editor:editor withSelection:NO]; + [TextInsertionUtils insertText:@"\u200B" at:lastRange.location additionalAttributes:nullptr input:input withSelection:NO]; } - // fix the selection - [editor->textView reactFocus]; - editor->textView.selectedRange = NSMakeRange(preAddSelection.location + postAddOffset, preAddSelection.length); + // fix the selection if needed + if(input->textView.focused) { + [input->textView reactFocus]; + input->textView.selectedRange = NSMakeRange(preAddSelection.location + postAddOffset, preAddSelection.length); + } } -+ (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text editor:(id)editor { ++ (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text input:(id)input { if(range.length != 1 || ![text isEqualToString:@""]) { return NO; } - ReactNativeRichTextEditorView *typedEditor = (ReactNativeRichTextEditorView *)editor; - if(typedEditor == nullptr) { return NO; } + EnrichedTextInputView *typedInput = (EnrichedTextInputView *)input; + if(typedInput == nullptr) { return NO; } - unichar character = [typedEditor->textView.textStorage.string characterAtIndex:range.location]; + unichar character = [typedInput->textView.textStorage.string characterAtIndex:range.location]; // zero-width space got backspaced if(character == 0x200B) { // in such case: remove the whole line without the endline if there is one - NSRange paragraphRange = [typedEditor->textView.textStorage.string paragraphRangeForRange:range]; + NSRange paragraphRange = [typedInput->textView.textStorage.string paragraphRangeForRange:range]; NSRange removalRange = paragraphRange; // if whole paragraph gets removed then 0 length for style removal NSRange styleRemovalRange = NSMakeRange(paragraphRange.location, 0); - if([[NSCharacterSet newlineCharacterSet] characterIsMember:[typedEditor->textView.textStorage.string characterAtIndex:NSMaxRange(paragraphRange) - 1]]) { + if([[NSCharacterSet newlineCharacterSet] characterIsMember:[typedInput->textView.textStorage.string characterAtIndex:NSMaxRange(paragraphRange) - 1]]) { // if endline is there, don't remove it removalRange = NSMakeRange(paragraphRange.location, paragraphRange.length - 1); // if endline is left then 1 length for style removal styleRemovalRange = NSMakeRange(paragraphRange.location, 1); } - [TextInsertionUtils replaceText:@"" at:removalRange additionalAttributes:nullptr editor:typedEditor withSelection:YES]; + [TextInsertionUtils replaceText:@"" at:removalRange additionalAttributes:nullptr input:typedInput withSelection:YES]; // and then remove associated styling - UnorderedListStyle *ulStyle = typedEditor->stylesDict[@([UnorderedListStyle getStyleType])]; - OrderedListStyle *olStyle = typedEditor->stylesDict[@([OrderedListStyle getStyleType])]; - BlockQuoteStyle *bqStyle = typedEditor->stylesDict[@([BlockQuoteStyle getStyleType])]; + UnorderedListStyle *ulStyle = typedInput->stylesDict[@([UnorderedListStyle getStyleType])]; + OrderedListStyle *olStyle = typedInput->stylesDict[@([OrderedListStyle getStyleType])]; + BlockQuoteStyle *bqStyle = typedInput->stylesDict[@([BlockQuoteStyle getStyleType])]; if([ulStyle detectStyle:styleRemovalRange]) { [ulStyle removeAttributes:styleRemovalRange]; From f5888b4d2c8b072109cd659ab10937919d5279ad Mon Sep 17 00:00:00 2001 From: szydlovsky <9szydlowski9@gmail.com> Date: Fri, 29 Aug 2025 17:45:56 +0200 Subject: [PATCH 4/8] chore: apply all the renames in the example ios app --- .../project.pbxproj | 114 +++++++++--------- .../ReactNativeRichTextEditorExample.xcscheme | 24 ++-- .../contents.xcworkspacedata | 2 +- .../AppDelegate.swift | 2 +- .../AppIcon.appiconset/Contents.json | 0 .../Images.xcassets/Contents.json | 0 .../Info.plist | 2 +- .../LaunchScreen.storyboard | 2 +- .../PrivacyInfo.xcprivacy | 0 example/ios/Podfile | 2 +- example/ios/Podfile.lock | 2 +- example/package.json | 2 +- package.json | 2 +- 13 files changed, 77 insertions(+), 77 deletions(-) rename example/ios/{ReactNativeRichTextEditorExample.xcodeproj => EnrichedTextInputExample.xcodeproj}/project.pbxproj (83%) rename example/ios/{ReactNativeRichTextEditorExample.xcodeproj => EnrichedTextInputExample.xcodeproj}/xcshareddata/xcschemes/ReactNativeRichTextEditorExample.xcscheme (74%) rename example/ios/{ReactNativeRichTextEditorExample.xcworkspace => EnrichedTextInputExample.xcworkspace}/contents.xcworkspacedata (72%) rename example/ios/{ReactNativeRichTextEditorExample => EnrichedTextInputExample}/AppDelegate.swift (95%) rename example/ios/{ReactNativeRichTextEditorExample => EnrichedTextInputExample}/Images.xcassets/AppIcon.appiconset/Contents.json (100%) rename example/ios/{ReactNativeRichTextEditorExample => EnrichedTextInputExample}/Images.xcassets/Contents.json (100%) rename example/ios/{ReactNativeRichTextEditorExample => EnrichedTextInputExample}/Info.plist (97%) rename example/ios/{ReactNativeRichTextEditorExample => EnrichedTextInputExample}/LaunchScreen.storyboard (93%) rename example/ios/{ReactNativeRichTextEditorExample => EnrichedTextInputExample}/PrivacyInfo.xcprivacy (100%) diff --git a/example/ios/ReactNativeRichTextEditorExample.xcodeproj/project.pbxproj b/example/ios/EnrichedTextInputExample.xcodeproj/project.pbxproj similarity index 83% rename from example/ios/ReactNativeRichTextEditorExample.xcodeproj/project.pbxproj rename to example/ios/EnrichedTextInputExample.xcodeproj/project.pbxproj index 85a6fc56f..630ee5059 100644 --- a/example/ios/ReactNativeRichTextEditorExample.xcodeproj/project.pbxproj +++ b/example/ios/EnrichedTextInputExample.xcodeproj/project.pbxproj @@ -26,40 +26,40 @@ 907A3D37EC6F4B9DA1B70348 /* CascadiaCode-ExtraLight.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 4A13A7631B3C499C989AC38A /* CascadiaCode-ExtraLight.ttf */; }; 95A487B0B0A94AFDA7B10C06 /* FontAwesome.ttf in Resources */ = {isa = PBXBuildFile; fileRef = D133E950DA6A4BC0A97DDFFE /* FontAwesome.ttf */; }; 970142F6180042E5964006A6 /* CascadiaCode-Light.ttf in Resources */ = {isa = PBXBuildFile; fileRef = DA76D9192FE24EC28C84DE79 /* CascadiaCode-Light.ttf */; }; - A988CCBE7099E5FBB91D5392 /* libPods-ReactNativeRichTextEditorExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 594377F3FC79DF09B28DA8C3 /* libPods-ReactNativeRichTextEditorExample.a */; }; + 9CCBAA226FD195143DDD2884 /* libPods-EnrichedTextInputExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D370084B15B932DA6ABD7D8 /* libPods-EnrichedTextInputExample.a */; }; D8B2038262614F14AE6245F0 /* CascadiaCode-SemiBoldItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 4DA2D2AB9E3743888DAD5779 /* CascadiaCode-SemiBoldItalic.ttf */; }; DCB0457B1CAE40B29979CDB9 /* CascadiaCode-VariableFont_wght.ttf in Resources */ = {isa = PBXBuildFile; fileRef = D384E64346204A8C8E773595 /* CascadiaCode-VariableFont_wght.ttf */; }; F83E68A3773947EA87D1FD9C /* CascadiaCode-SemiBold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 3FD646A3FF0F4F33AC65021F /* CascadiaCode-SemiBold.ttf */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ - 13B07F961A680F5B00A75B9A /* ReactNativeRichTextEditorExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ReactNativeRichTextEditorExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = ReactNativeRichTextEditorExample/Images.xcassets; sourceTree = ""; }; - 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = ReactNativeRichTextEditorExample/Info.plist; sourceTree = ""; }; - 13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = PrivacyInfo.xcprivacy; path = ReactNativeRichTextEditorExample/PrivacyInfo.xcprivacy; sourceTree = ""; }; + 13B07F961A680F5B00A75B9A /* EnrichedTextInputExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = EnrichedTextInputExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = EnrichedTextInputExample/Images.xcassets; sourceTree = ""; }; + 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = EnrichedTextInputExample/Info.plist; sourceTree = ""; }; + 13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = PrivacyInfo.xcprivacy; path = EnrichedTextInputExample/PrivacyInfo.xcprivacy; sourceTree = ""; }; 3A18DEB91C24449AA3ECE59A /* CascadiaCode-Italic-VariableFont_wght.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-Italic-VariableFont_wght.ttf"; path = "../assets/fonts/Cascadia_Code/CascadiaCode-Italic-VariableFont_wght.ttf"; sourceTree = ""; }; - 3C13A583FC86796D0F36DF7C /* Pods-ReactNativeRichTextEditorExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeRichTextEditorExample.release.xcconfig"; path = "Target Support Files/Pods-ReactNativeRichTextEditorExample/Pods-ReactNativeRichTextEditorExample.release.xcconfig"; sourceTree = ""; }; 3FD646A3FF0F4F33AC65021F /* CascadiaCode-SemiBold.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-SemiBold.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-SemiBold.ttf"; sourceTree = ""; }; 4A13A7631B3C499C989AC38A /* CascadiaCode-ExtraLight.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-ExtraLight.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-ExtraLight.ttf"; sourceTree = ""; }; 4DA2D2AB9E3743888DAD5779 /* CascadiaCode-SemiBoldItalic.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-SemiBoldItalic.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-SemiBoldItalic.ttf"; sourceTree = ""; }; 4E36300E55D4493B9BE898E6 /* CascadiaCode-Regular.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-Regular.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-Regular.ttf"; sourceTree = ""; }; - 594377F3FC79DF09B28DA8C3 /* libPods-ReactNativeRichTextEditorExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ReactNativeRichTextEditorExample.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 5D1BB596339A4F8E8CBC2087 /* CascadiaCode-BoldItalic.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-BoldItalic.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-BoldItalic.ttf"; sourceTree = ""; }; 6352E13F84F841D5A2BA25B4 /* CascadiaCode-Italic.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-Italic.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-Italic.ttf"; sourceTree = ""; }; 674C8E7598D647768ECEC0E1 /* OFL.txt */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = OFL.txt; path = ../assets/fonts/Cascadia_Code/OFL.txt; sourceTree = ""; }; - 761780EC2CA45674006654EE /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AppDelegate.swift; path = ReactNativeRichTextEditorExample/AppDelegate.swift; sourceTree = ""; }; + 6D370084B15B932DA6ABD7D8 /* libPods-EnrichedTextInputExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-EnrichedTextInputExample.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 761780EC2CA45674006654EE /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AppDelegate.swift; path = EnrichedTextInputExample/AppDelegate.swift; sourceTree = ""; }; 78D6C09519344432B162E948 /* CascadiaCode-MediumItalic.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-MediumItalic.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-MediumItalic.ttf"; sourceTree = ""; }; 79452663257A4B73B2308643 /* CascadiaCode-Bold.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-Bold.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-Bold.ttf"; sourceTree = ""; }; 7DDEBA1C438F415493ECFAB7 /* CascadiaCode-ExtraLightItalic.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-ExtraLightItalic.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-ExtraLightItalic.ttf"; sourceTree = ""; }; 7FD036FA17B24AAFA7082B2A /* CascadiaCode-LightItalic.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-LightItalic.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-LightItalic.ttf"; sourceTree = ""; }; - 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = ReactNativeRichTextEditorExample/LaunchScreen.storyboard; sourceTree = ""; }; + 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = EnrichedTextInputExample/LaunchScreen.storyboard; sourceTree = ""; }; 87375222174145AD85B4DE62 /* CascadiaCode-Medium.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-Medium.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-Medium.ttf"; sourceTree = ""; }; 8A425B9B75B9488EA0FDF624 /* README.txt */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = README.txt; path = ../assets/fonts/Cascadia_Code/README.txt; sourceTree = ""; }; + 8D30641E04B3C92750094BD1 /* Pods-EnrichedTextInputExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-EnrichedTextInputExample.release.xcconfig"; path = "Target Support Files/Pods-EnrichedTextInputExample/Pods-EnrichedTextInputExample.release.xcconfig"; sourceTree = ""; }; + ABB962282C7DB4F364360154 /* Pods-EnrichedTextInputExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-EnrichedTextInputExample.debug.xcconfig"; path = "Target Support Files/Pods-EnrichedTextInputExample/Pods-EnrichedTextInputExample.debug.xcconfig"; sourceTree = ""; }; C667157990F34428AEE8CC93 /* FontAwesome.json */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = FontAwesome.json; path = ../assets/icons/FontAwesome.json; sourceTree = ""; }; D133E950DA6A4BC0A97DDFFE /* FontAwesome.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = FontAwesome.ttf; path = ../assets/icons/FontAwesome.ttf; sourceTree = ""; }; D384E64346204A8C8E773595 /* CascadiaCode-VariableFont_wght.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-VariableFont_wght.ttf"; path = "../assets/fonts/Cascadia_Code/CascadiaCode-VariableFont_wght.ttf"; sourceTree = ""; }; DA76D9192FE24EC28C84DE79 /* CascadiaCode-Light.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-Light.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-Light.ttf"; sourceTree = ""; }; - E6A46588CE906F8A9AC9DB45 /* Pods-ReactNativeRichTextEditorExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeRichTextEditorExample.debug.xcconfig"; path = "Target Support Files/Pods-ReactNativeRichTextEditorExample/Pods-ReactNativeRichTextEditorExample.debug.xcconfig"; sourceTree = ""; }; ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; /* End PBXFileReference section */ @@ -68,14 +68,14 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - A988CCBE7099E5FBB91D5392 /* libPods-ReactNativeRichTextEditorExample.a in Frameworks */, + 9CCBAA226FD195143DDD2884 /* libPods-EnrichedTextInputExample.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 13B07FAE1A68108700A75B9A /* ReactNativeRichTextEditorExample */ = { + 13B07FAE1A68108700A75B9A /* EnrichedTextInputExample */ = { isa = PBXGroup; children = ( 13B07FB51A68108700A75B9A /* Images.xcassets */, @@ -84,14 +84,14 @@ 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */, 13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */, ); - name = ReactNativeRichTextEditorExample; + name = EnrichedTextInputExample; sourceTree = ""; }; 2D16E6871FA4F8E400B85C8A /* Frameworks */ = { isa = PBXGroup; children = ( ED297162215061F000B7C4FE /* JavaScriptCore.framework */, - 594377F3FC79DF09B28DA8C3 /* libPods-ReactNativeRichTextEditorExample.a */, + 6D370084B15B932DA6ABD7D8 /* libPods-EnrichedTextInputExample.a */, ); name = Frameworks; sourceTree = ""; @@ -106,7 +106,7 @@ 83CBB9F61A601CBA00E9B192 = { isa = PBXGroup; children = ( - 13B07FAE1A68108700A75B9A /* ReactNativeRichTextEditorExample */, + 13B07FAE1A68108700A75B9A /* EnrichedTextInputExample */, 832341AE1AAA6A7D00B99B32 /* Libraries */, 83CBBA001A601CBA00E9B192 /* Products */, 2D16E6871FA4F8E400B85C8A /* Frameworks */, @@ -121,7 +121,7 @@ 83CBBA001A601CBA00E9B192 /* Products */ = { isa = PBXGroup; children = ( - 13B07F961A680F5B00A75B9A /* ReactNativeRichTextEditorExample.app */, + 13B07F961A680F5B00A75B9A /* EnrichedTextInputExample.app */, ); name = Products; sourceTree = ""; @@ -129,8 +129,8 @@ BBD78D7AC51CEA395F1C20DB /* Pods */ = { isa = PBXGroup; children = ( - E6A46588CE906F8A9AC9DB45 /* Pods-ReactNativeRichTextEditorExample.debug.xcconfig */, - 3C13A583FC86796D0F36DF7C /* Pods-ReactNativeRichTextEditorExample.release.xcconfig */, + ABB962282C7DB4F364360154 /* Pods-EnrichedTextInputExample.debug.xcconfig */, + 8D30641E04B3C92750094BD1 /* Pods-EnrichedTextInputExample.release.xcconfig */, ); path = Pods; sourceTree = ""; @@ -164,25 +164,25 @@ /* End PBXGroup section */ /* Begin PBXNativeTarget section */ - 13B07F861A680F5B00A75B9A /* ReactNativeRichTextEditorExample */ = { + 13B07F861A680F5B00A75B9A /* EnrichedTextInputExample */ = { isa = PBXNativeTarget; - buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "ReactNativeRichTextEditorExample" */; + buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "EnrichedTextInputExample" */; buildPhases = ( - 69C011D95EDBCACAB3FC1113 /* [CP] Check Pods Manifest.lock */, + 4981A167C0063A82876DD1AB /* [CP] Check Pods Manifest.lock */, 13B07F871A680F5B00A75B9A /* Sources */, 13B07F8C1A680F5B00A75B9A /* Frameworks */, 13B07F8E1A680F5B00A75B9A /* Resources */, 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */, - 53EBC749589386D90FE2E60D /* [CP] Embed Pods Frameworks */, - B1576F9548D80B049BBF8E31 /* [CP] Copy Pods Resources */, + 75C9505AFC16ED96EE5E9ED4 /* [CP] Embed Pods Frameworks */, + B600D4E6CF246F817102A773 /* [CP] Copy Pods Resources */, ); buildRules = ( ); dependencies = ( ); - name = ReactNativeRichTextEditorExample; - productName = ReactNativeRichTextEditorExample; - productReference = 13B07F961A680F5B00A75B9A /* ReactNativeRichTextEditorExample.app */; + name = EnrichedTextInputExample; + productName = EnrichedTextInputExample; + productReference = 13B07F961A680F5B00A75B9A /* EnrichedTextInputExample.app */; productType = "com.apple.product-type.application"; }; /* End PBXNativeTarget section */ @@ -198,7 +198,7 @@ }; }; }; - buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "ReactNativeRichTextEditorExample" */; + buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "EnrichedTextInputExample" */; compatibilityVersion = "Xcode 12.0"; developmentRegion = en; hasScannedForEncodings = 0; @@ -211,7 +211,7 @@ projectDirPath = ""; projectRoot = ""; targets = ( - 13B07F861A680F5B00A75B9A /* ReactNativeRichTextEditorExample */, + 13B07F861A680F5B00A75B9A /* EnrichedTextInputExample */, ); }; /* End PBXProject section */ @@ -264,60 +264,60 @@ shellPath = /bin/sh; shellScript = "set -e\n\nWITH_ENVIRONMENT=\"$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"$REACT_NATIVE_PATH/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n"; }; - 53EBC749589386D90FE2E60D /* [CP] Embed Pods Frameworks */ = { + 4981A167C0063A82876DD1AB /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-ReactNativeRichTextEditorExample/Pods-ReactNativeRichTextEditorExample-frameworks-${CONFIGURATION}-input-files.xcfilelist", ); - name = "[CP] Embed Pods Frameworks"; + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; outputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-ReactNativeRichTextEditorExample/Pods-ReactNativeRichTextEditorExample-frameworks-${CONFIGURATION}-output-files.xcfilelist", + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-EnrichedTextInputExample-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-ReactNativeRichTextEditorExample/Pods-ReactNativeRichTextEditorExample-frameworks.sh\"\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - 69C011D95EDBCACAB3FC1113 /* [CP] Check Pods Manifest.lock */ = { + 75C9505AFC16ED96EE5E9ED4 /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-EnrichedTextInputExample/Pods-EnrichedTextInputExample-frameworks-${CONFIGURATION}-input-files.xcfilelist", ); - inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; + name = "[CP] Embed Pods Frameworks"; outputFileListPaths = ( - ); - outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-ReactNativeRichTextEditorExample-checkManifestLockResult.txt", + "${PODS_ROOT}/Target Support Files/Pods-EnrichedTextInputExample/Pods-EnrichedTextInputExample-frameworks-${CONFIGURATION}-output-files.xcfilelist", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-EnrichedTextInputExample/Pods-EnrichedTextInputExample-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; - B1576F9548D80B049BBF8E31 /* [CP] Copy Pods Resources */ = { + B600D4E6CF246F817102A773 /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-ReactNativeRichTextEditorExample/Pods-ReactNativeRichTextEditorExample-resources-${CONFIGURATION}-input-files.xcfilelist", + "${PODS_ROOT}/Target Support Files/Pods-EnrichedTextInputExample/Pods-EnrichedTextInputExample-resources-${CONFIGURATION}-input-files.xcfilelist", ); name = "[CP] Copy Pods Resources"; outputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-ReactNativeRichTextEditorExample/Pods-ReactNativeRichTextEditorExample-resources-${CONFIGURATION}-output-files.xcfilelist", + "${PODS_ROOT}/Target Support Files/Pods-EnrichedTextInputExample/Pods-EnrichedTextInputExample-resources-${CONFIGURATION}-output-files.xcfilelist", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-ReactNativeRichTextEditorExample/Pods-ReactNativeRichTextEditorExample-resources.sh\"\n"; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-EnrichedTextInputExample/Pods-EnrichedTextInputExample-resources.sh\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ @@ -336,13 +336,13 @@ /* Begin XCBuildConfiguration section */ 13B07F941A680F5B00A75B9A /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = E6A46588CE906F8A9AC9DB45 /* Pods-ReactNativeRichTextEditorExample.debug.xcconfig */; + baseConfigurationReference = ABB962282C7DB4F364360154 /* Pods-EnrichedTextInputExample.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = 1; ENABLE_BITCODE = NO; - INFOPLIST_FILE = ReactNativeRichTextEditorExample/Info.plist; + INFOPLIST_FILE = EnrichedTextInputExample/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 15.1; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -354,8 +354,8 @@ "-ObjC", "-lc++", ); - PRODUCT_BUNDLE_IDENTIFIER = swmansion.reactnativerichtexteditor.example; - PRODUCT_NAME = ReactNativeRichTextEditorExample; + PRODUCT_BUNDLE_IDENTIFIER = swmansion.enrichedtextinputexample.example; + PRODUCT_NAME = EnrichedTextInputExample; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; @@ -364,12 +364,12 @@ }; 13B07F951A680F5B00A75B9A /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 3C13A583FC86796D0F36DF7C /* Pods-ReactNativeRichTextEditorExample.release.xcconfig */; + baseConfigurationReference = 8D30641E04B3C92750094BD1 /* Pods-EnrichedTextInputExample.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = 1; - INFOPLIST_FILE = ReactNativeRichTextEditorExample/Info.plist; + INFOPLIST_FILE = EnrichedTextInputExample/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 15.1; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -381,8 +381,8 @@ "-ObjC", "-lc++", ); - PRODUCT_BUNDLE_IDENTIFIER = swmansion.reactnativerichtexteditor.example; - PRODUCT_NAME = ReactNativeRichTextEditorExample; + PRODUCT_BUNDLE_IDENTIFIER = swmansion.enrichedtextinputexample.example; + PRODUCT_NAME = EnrichedTextInputExample; SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; }; @@ -543,7 +543,7 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "ReactNativeRichTextEditorExample" */ = { + 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "EnrichedTextInputExample" */ = { isa = XCConfigurationList; buildConfigurations = ( 13B07F941A680F5B00A75B9A /* Debug */, @@ -552,7 +552,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "ReactNativeRichTextEditorExample" */ = { + 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "EnrichedTextInputExample" */ = { isa = XCConfigurationList; buildConfigurations = ( 83CBBA201A601CBA00E9B192 /* Debug */, diff --git a/example/ios/ReactNativeRichTextEditorExample.xcodeproj/xcshareddata/xcschemes/ReactNativeRichTextEditorExample.xcscheme b/example/ios/EnrichedTextInputExample.xcodeproj/xcshareddata/xcschemes/ReactNativeRichTextEditorExample.xcscheme similarity index 74% rename from example/ios/ReactNativeRichTextEditorExample.xcodeproj/xcshareddata/xcschemes/ReactNativeRichTextEditorExample.xcscheme rename to example/ios/EnrichedTextInputExample.xcodeproj/xcshareddata/xcschemes/ReactNativeRichTextEditorExample.xcscheme index e526962ae..8ad6179b8 100644 --- a/example/ios/ReactNativeRichTextEditorExample.xcodeproj/xcshareddata/xcschemes/ReactNativeRichTextEditorExample.xcscheme +++ b/example/ios/EnrichedTextInputExample.xcodeproj/xcshareddata/xcschemes/ReactNativeRichTextEditorExample.xcscheme @@ -15,9 +15,9 @@ + BuildableName = "EnrichedTextInputExample.app" + BlueprintName = "EnrichedTextInputExample" + ReferencedContainer = "container:EnrichedTextInputExample.xcodeproj"> @@ -33,9 +33,9 @@ + BuildableName = "EnrichedTextInputExampleTests.xctest" + BlueprintName = "EnrichedTextInputExampleTests" + ReferencedContainer = "container:EnrichedTextInputExample.xcodeproj"> @@ -55,9 +55,9 @@ + BuildableName = "EnrichedTextInputExample.app" + BlueprintName = "EnrichedTextInputExample" + ReferencedContainer = "container:EnrichedTextInputExample.xcodeproj"> @@ -72,9 +72,9 @@ + BuildableName = "EnrichedTextInputExample.app" + BlueprintName = "EnrichedTextInputExample" + ReferencedContainer = "container:EnrichedTextInputExample.xcodeproj"> diff --git a/example/ios/ReactNativeRichTextEditorExample.xcworkspace/contents.xcworkspacedata b/example/ios/EnrichedTextInputExample.xcworkspace/contents.xcworkspacedata similarity index 72% rename from example/ios/ReactNativeRichTextEditorExample.xcworkspace/contents.xcworkspacedata rename to example/ios/EnrichedTextInputExample.xcworkspace/contents.xcworkspacedata index c408a0603..86f37dc9f 100644 --- a/example/ios/ReactNativeRichTextEditorExample.xcworkspace/contents.xcworkspacedata +++ b/example/ios/EnrichedTextInputExample.xcworkspace/contents.xcworkspacedata @@ -2,7 +2,7 @@ + location = "group:EnrichedTextInputExample.xcodeproj"> diff --git a/example/ios/ReactNativeRichTextEditorExample/AppDelegate.swift b/example/ios/EnrichedTextInputExample/AppDelegate.swift similarity index 95% rename from example/ios/ReactNativeRichTextEditorExample/AppDelegate.swift rename to example/ios/EnrichedTextInputExample/AppDelegate.swift index 60b85f690..71f4f9bd2 100644 --- a/example/ios/ReactNativeRichTextEditorExample/AppDelegate.swift +++ b/example/ios/EnrichedTextInputExample/AppDelegate.swift @@ -24,7 +24,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { window = UIWindow(frame: UIScreen.main.bounds) factory.startReactNative( - withModuleName: "ReactNativeRichTextEditorExample", + withModuleName: "EnrichedTextInputExample", in: window, launchOptions: launchOptions ) diff --git a/example/ios/ReactNativeRichTextEditorExample/Images.xcassets/AppIcon.appiconset/Contents.json b/example/ios/EnrichedTextInputExample/Images.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from example/ios/ReactNativeRichTextEditorExample/Images.xcassets/AppIcon.appiconset/Contents.json rename to example/ios/EnrichedTextInputExample/Images.xcassets/AppIcon.appiconset/Contents.json diff --git a/example/ios/ReactNativeRichTextEditorExample/Images.xcassets/Contents.json b/example/ios/EnrichedTextInputExample/Images.xcassets/Contents.json similarity index 100% rename from example/ios/ReactNativeRichTextEditorExample/Images.xcassets/Contents.json rename to example/ios/EnrichedTextInputExample/Images.xcassets/Contents.json diff --git a/example/ios/ReactNativeRichTextEditorExample/Info.plist b/example/ios/EnrichedTextInputExample/Info.plist similarity index 97% rename from example/ios/ReactNativeRichTextEditorExample/Info.plist rename to example/ios/EnrichedTextInputExample/Info.plist index 6ec86947b..75363b512 100644 --- a/example/ios/ReactNativeRichTextEditorExample/Info.plist +++ b/example/ios/EnrichedTextInputExample/Info.plist @@ -5,7 +5,7 @@ CFBundleDevelopmentRegion en CFBundleDisplayName - ReactNativeRichTextEditorExample + EnrichedTextInputExample CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier diff --git a/example/ios/ReactNativeRichTextEditorExample/LaunchScreen.storyboard b/example/ios/EnrichedTextInputExample/LaunchScreen.storyboard similarity index 93% rename from example/ios/ReactNativeRichTextEditorExample/LaunchScreen.storyboard rename to example/ios/EnrichedTextInputExample/LaunchScreen.storyboard index 065e079df..9e519f9d7 100644 --- a/example/ios/ReactNativeRichTextEditorExample/LaunchScreen.storyboard +++ b/example/ios/EnrichedTextInputExample/LaunchScreen.storyboard @@ -16,7 +16,7 @@ -