react-native-enriched 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/android/build.gradle +3 -3
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerDelegate.java +3 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerInterface.java +1 -0
- package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ComponentDescriptors.cpp +1 -1
- package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ComponentDescriptors.h +1 -1
- package/{ios/generated/RNEnrichedTextInputViewSpec → android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec}/EventEmitters.cpp +31 -29
- package/{ios/generated/RNEnrichedTextInputViewSpec → android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec}/EventEmitters.h +22 -25
- package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/Props.h +57 -0
- package/android/gradle.properties +5 -5
- package/android/src/main/java/com/swmansion/enriched/{EnrichedTextInputViewPackage.kt → ReactNativeEnrichedPackage.kt} +3 -2
- package/android/src/main/java/com/swmansion/enriched/{utils → common}/AsyncDrawable.kt +40 -8
- package/android/src/main/java/com/swmansion/enriched/common/CheckboxDrawable.kt +81 -0
- package/android/src/main/java/com/swmansion/enriched/{utils → common}/EnrichedConstants.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/common/EnrichedStyle.kt +57 -0
- package/android/src/main/java/com/swmansion/enriched/{spans/utils → common}/ForceRedrawSpan.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/common/MentionStyle.kt +7 -0
- package/android/src/main/java/com/swmansion/enriched/{utils → common}/ResourceManager.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/{utils → common/parser}/EnrichedParser.java +126 -99
- package/android/src/main/java/com/swmansion/enriched/common/parser/EnrichedSpanFactory.kt +79 -0
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedBlockQuoteSpan.kt +9 -13
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedBoldSpan.kt +12 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedCheckboxListSpan.kt +91 -0
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedCodeBlockSpan.kt +8 -12
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH1Span.kt +20 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH2Span.kt +20 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH3Span.kt +20 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH4Span.kt +21 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH5Span.kt +20 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH6Span.kt +20 -0
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedImageSpan.kt +43 -38
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedInlineCodeSpan.kt +7 -11
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedItalicSpan.kt +12 -0
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedLinkSpan.kt +7 -11
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedMentionSpan.kt +6 -10
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedOrderedListSpan.kt +12 -21
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedStrikeThroughSpan.kt +11 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedUnderlineSpan.kt +11 -0
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedUnorderedListSpan.kt +9 -13
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/interfaces/EnrichedBlockSpan.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/interfaces/EnrichedHeadingSpan.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/common/spans/interfaces/EnrichedInlineSpan.kt +3 -0
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/interfaces/EnrichedParagraphSpan.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/common/spans/interfaces/EnrichedSpan.kt +3 -0
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/interfaces/EnrichedZeroWidthSpaceSpan.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/{EnrichedTextInputConnectionWrapper.kt → textinput/EnrichedTextInputConnectionWrapper.kt} +2 -2
- package/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputSpannableFactory.kt +83 -0
- package/android/src/main/java/com/swmansion/enriched/{EnrichedTextInputView.kt → textinput/EnrichedTextInputView.kt} +87 -51
- package/android/src/main/java/com/swmansion/enriched/{EnrichedTextInputViewLayoutManager.kt → textinput/EnrichedTextInputViewLayoutManager.kt} +1 -1
- package/android/src/main/java/com/swmansion/enriched/{EnrichedTextInputViewManager.kt → textinput/EnrichedTextInputViewManager.kt} +24 -17
- package/android/src/main/java/com/swmansion/enriched/{MeasurementStore.kt → textinput/MeasurementStore.kt} +5 -4
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/MentionHandler.kt +2 -2
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnChangeHtmlEvent.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnChangeSelectionEvent.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnChangeStateEvent.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnChangeTextEvent.kt +2 -2
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnInputBlurEvent.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnInputFocusEvent.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnInputKeyPressEvent.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnLinkDetectedEvent.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnMentionDetectedEvent.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnMentionEvent.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnPasteImagesEvent.kt +47 -0
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnRequestHtmlResultEvent.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputBlockQuoteSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputBoldSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputCheckboxListSpan.kt +15 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputCodeBlockSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH1Span.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH2Span.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH3Span.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH4Span.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH5Span.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH6Span.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputImageSpan.kt +36 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputInlineCodeSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputItalicSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputLinkSpan.kt +15 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputMentionSpan.kt +18 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputOrderedListSpan.kt +21 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputStrikeThroughSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputUnderlineSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputUnorderedListSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/{spans → textinput/spans}/EnrichedSpans.kt +39 -30
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/interfaces/EnrichedInputSpan.kt +10 -0
- package/android/src/main/java/com/swmansion/enriched/{styles → textinput/styles}/HtmlStyle.kt +58 -43
- package/android/src/main/java/com/swmansion/enriched/{styles → textinput/styles}/InlineStyles.kt +4 -4
- package/android/src/main/java/com/swmansion/enriched/{styles → textinput/styles}/ListStyles.kt +77 -26
- package/android/src/main/java/com/swmansion/enriched/{styles → textinput/styles}/ParagraphStyles.kt +11 -11
- package/android/src/main/java/com/swmansion/enriched/{styles → textinput/styles}/ParametrizedStyles.kt +19 -19
- package/android/src/main/java/com/swmansion/enriched/{utils → textinput/utils}/EnrichedEditableFactory.kt +2 -2
- package/android/src/main/java/com/swmansion/enriched/{utils → textinput/utils}/EnrichedSelection.kt +15 -14
- package/android/src/main/java/com/swmansion/enriched/{utils → textinput/utils}/EnrichedSpanState.kt +15 -50
- package/android/src/main/java/com/swmansion/enriched/{utils → textinput/utils}/EnrichedSpannable.kt +3 -3
- package/android/src/main/java/com/swmansion/enriched/{utils → textinput/utils}/EnrichedSpannableStringBuilder.kt +2 -1
- package/android/src/main/java/com/swmansion/enriched/textinput/utils/RichContentReceiver.kt +127 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/utils/Utils.kt +106 -0
- package/android/src/main/java/com/swmansion/enriched/{watchers → textinput/watchers}/EnrichedSpanWatcher.kt +10 -10
- package/android/src/main/java/com/swmansion/enriched/{watchers → textinput/watchers}/EnrichedTextWatcher.kt +3 -3
- package/android/src/main/new_arch/CMakeLists.txt +1 -1
- package/android/src/main/new_arch/ReactNativeEnrichedSpec.cpp +11 -0
- package/android/src/main/new_arch/ReactNativeEnrichedSpec.h +15 -0
- package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputMeasurementManager.h +1 -1
- package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputShadowNode.h +2 -2
- package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/conversions.h +1 -1
- package/ios/EnrichedTextInputView.h +1 -0
- package/ios/EnrichedTextInputView.mm +266 -55
- package/ios/config/InputConfig.h +10 -0
- package/ios/config/InputConfig.mm +119 -0
- package/ios/extensions/ImageExtension.h +35 -0
- package/ios/extensions/ImageExtension.mm +156 -0
- package/ios/extensions/LayoutManagerExtension.mm +115 -95
- package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ComponentDescriptors.cpp +1 -1
- package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ComponentDescriptors.h +1 -1
- package/{android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec → ios/generated/ReactNativeEnrichedSpec}/EventEmitters.cpp +31 -29
- package/{android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec → ios/generated/ReactNativeEnrichedSpec}/EventEmitters.h +22 -25
- package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/Props.h +57 -0
- package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/RCTComponentViewHelpers.h +21 -0
- package/ios/inputParser/InputParser.mm +135 -8
- package/ios/inputTextView/InputTextView.mm +118 -0
- package/ios/interfaces/ImageAttachment.h +1 -0
- package/ios/interfaces/ImageAttachment.mm +14 -4
- package/ios/interfaces/StyleHeaders.h +13 -2
- package/ios/interfaces/StyleTypeEnum.h +1 -0
- package/ios/internals/EnrichedTextInputViewState.cpp +6 -6
- package/ios/styles/CheckboxListStyle.mm +321 -0
- package/ios/styles/H1Style.mm +3 -0
- package/ios/styles/H2Style.mm +3 -0
- package/ios/styles/H3Style.mm +3 -0
- package/ios/styles/H4Style.mm +3 -0
- package/ios/styles/H5Style.mm +3 -0
- package/ios/styles/H6Style.mm +3 -0
- package/ios/styles/HeadingStyleBase.mm +150 -78
- package/ios/utils/CheckboxHitTestUtils.h +10 -0
- package/ios/utils/CheckboxHitTestUtils.mm +123 -0
- package/ios/utils/ParagraphAttributesUtils.mm +83 -53
- package/ios/utils/TextBlockTapGestureRecognizer.h +17 -0
- package/ios/utils/TextBlockTapGestureRecognizer.mm +56 -0
- package/ios/utils/ZeroWidthSpaceUtils.mm +14 -3
- package/lib/module/EnrichedTextInput.js +36 -11
- package/lib/module/EnrichedTextInput.js.map +1 -1
- package/lib/module/{EnrichedTextInputNativeComponent.ts → spec/EnrichedTextInputNativeComponent.ts} +40 -9
- package/lib/module/types.js +4 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils/normalizeHtmlStyle.js +6 -0
- package/lib/module/utils/normalizeHtmlStyle.js.map +1 -1
- package/lib/module/utils/nullthrows.js +9 -0
- package/lib/module/utils/nullthrows.js.map +1 -0
- package/lib/typescript/src/EnrichedTextInput.d.ts +9 -49
- package/lib/typescript/src/EnrichedTextInput.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/{EnrichedTextInputNativeComponent.d.ts → spec/EnrichedTextInputNativeComponent.d.ts} +33 -8
- package/lib/typescript/src/spec/EnrichedTextInputNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +58 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/utils/normalizeHtmlStyle.d.ts +2 -2
- package/lib/typescript/src/utils/normalizeHtmlStyle.d.ts.map +1 -1
- package/lib/typescript/src/utils/nullthrows.d.ts +2 -0
- package/lib/typescript/src/utils/nullthrows.d.ts.map +1 -0
- package/lib/typescript/src/utils/regexParser.d.ts +1 -1
- package/lib/typescript/src/utils/regexParser.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/EnrichedTextInput.tsx +49 -62
- package/src/index.tsx +3 -1
- package/src/{EnrichedTextInputNativeComponent.ts → spec/EnrichedTextInputNativeComponent.ts} +40 -9
- package/src/types.ts +59 -0
- package/src/utils/normalizeHtmlStyle.ts +8 -5
- package/src/utils/nullthrows.ts +7 -0
- package/src/utils/regexParser.ts +1 -1
- package/android/src/main/java/com/swmansion/enriched/events/OnChangeStateDeprecatedEvent.kt +0 -21
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBoldSpan.kt +0 -17
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH1Span.kt +0 -24
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH2Span.kt +0 -24
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH3Span.kt +0 -24
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH4Span.kt +0 -24
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH5Span.kt +0 -24
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH6Span.kt +0 -24
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedItalicSpan.kt +0 -16
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedStrikeThroughSpan.kt +0 -15
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnderlineSpan.kt +0 -15
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedInlineSpan.kt +0 -3
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedSpan.kt +0 -9
- package/android/src/main/java/com/swmansion/enriched/utils/Utils.kt +0 -21
- package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.cpp +0 -22
- package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.h +0 -26
- package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts.map +0 -1
- /package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/Props.cpp +0 -0
- /package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ShadowNodes.cpp +0 -0
- /package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ShadowNodes.h +0 -0
- /package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/States.cpp +0 -0
- /package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/States.h +0 -0
- /package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputComponentDescriptor.h +0 -0
- /package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputMeasurementManager.cpp +0 -0
- /package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputShadowNode.cpp +0 -0
- /package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputState.cpp +0 -0
- /package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputState.h +0 -0
- /package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/Props.cpp +0 -0
- /package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ShadowNodes.cpp +0 -0
- /package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ShadowNodes.h +0 -0
- /package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/States.cpp +0 -0
- /package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/States.h +0 -0
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<img src="https://github.com/user-attachments/assets/
|
|
1
|
+
<img src="https://github.com/user-attachments/assets/6963e203-38c8-4209-b1b2-1ff65f6765f9" alt="react-native-enriched by Software Mansion" width="100%">
|
|
2
2
|
|
|
3
3
|
# react-native-enriched
|
|
4
4
|
|
|
@@ -40,7 +40,7 @@ We can help you build your next dream product –
|
|
|
40
40
|
## Prerequisites
|
|
41
41
|
|
|
42
42
|
- `react-native-enriched` currently supports only Android and iOS platforms
|
|
43
|
-
- It works only with [the React Native New Architecture (Fabric)](https://reactnative.dev/architecture/landing-page) and supports following React Native releases: `0.79`, `0.80`, `0.81`, `0.82` and `0.
|
|
43
|
+
- It works only with [the React Native New Architecture (Fabric)](https://reactnative.dev/architecture/landing-page) and supports following React Native releases: `0.79`, `0.80`, `0.81`, `0.82`, `0.83` and `0.84`.
|
|
44
44
|
|
|
45
45
|
## Installation
|
|
46
46
|
|
|
@@ -105,8 +105,8 @@ export default function App() {
|
|
|
105
105
|
style={styles.input}
|
|
106
106
|
/>
|
|
107
107
|
<Button
|
|
108
|
-
title={stylesState?.
|
|
109
|
-
color={stylesState?.
|
|
108
|
+
title={stylesState?.bold.isActive ? 'Unbold' : 'Bold'}
|
|
109
|
+
color={stylesState?.bold.isActive ? 'green' : 'gray'}
|
|
110
110
|
onPress={() => ref.current?.toggleBold()}
|
|
111
111
|
/>
|
|
112
112
|
</View>
|
|
@@ -152,6 +152,7 @@ Supported styles:
|
|
|
152
152
|
- blockquote
|
|
153
153
|
- ordered list
|
|
154
154
|
- unordered list
|
|
155
|
+
- checkbox list
|
|
155
156
|
|
|
156
157
|
Each of the styles can be toggled the same way as in the example from [usage section](#usage); call a proper `toggle` function on the component ref.
|
|
157
158
|
|
|
@@ -229,6 +230,7 @@ You can find some examples in the [usage section](#usage) or in the example app.
|
|
|
229
230
|
- [onLinkDetected](docs/API_REFERENCE.md#onlinkdetected) - returns link's detailed info whenever user selection is near one.
|
|
230
231
|
- [onMentionDetected](docs/API_REFERENCE.md#onmentiondetected) - returns mention's detailed info whenever user selection is near one.
|
|
231
232
|
- [onKeyPress](docs/API_REFERENCE.md#onkeypress) - emits whenever a key is pressed. Follows react-native TextInput's onKeyPress event [spec](https://reactnative.dev/docs/textinput#onkeypress).
|
|
233
|
+
- [onPasteImages](docs/API_REFERENCE.md#onpasteimages) - returns an array of images details whenever an image/GIF is pasted into the input.
|
|
232
234
|
|
|
233
235
|
## Customizing \<EnrichedTextInput /> styles
|
|
234
236
|
|
package/android/build.gradle
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
buildscript {
|
|
2
2
|
ext.getExtOrDefault = {name ->
|
|
3
|
-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['
|
|
3
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['ReactNativeEnriched_' + name]
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
repositories {
|
|
@@ -27,7 +27,7 @@ apply plugin: "com.facebook.react"
|
|
|
27
27
|
apply from: "lint.gradle"
|
|
28
28
|
|
|
29
29
|
def getExtOrIntegerDefault(name) {
|
|
30
|
-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["
|
|
30
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["ReactNativeEnriched_" + name]).toInteger()
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
def supportsNamespace() {
|
|
@@ -101,6 +101,6 @@ dependencies {
|
|
|
101
101
|
|
|
102
102
|
react {
|
|
103
103
|
jsRootDir = file("../src/")
|
|
104
|
-
libraryName = "
|
|
104
|
+
libraryName = "ReactNativeEnriched"
|
|
105
105
|
codegenJavaPackageName = "com.swmansion.enriched"
|
|
106
106
|
}
|
|
@@ -150,6 +150,9 @@ public class EnrichedTextInputViewManagerDelegate<T extends View, U extends Base
|
|
|
150
150
|
case "toggleUnorderedList":
|
|
151
151
|
mViewManager.toggleUnorderedList(view);
|
|
152
152
|
break;
|
|
153
|
+
case "toggleCheckboxList":
|
|
154
|
+
mViewManager.toggleCheckboxList(view, args.getBoolean(0));
|
|
155
|
+
break;
|
|
153
156
|
case "addLink":
|
|
154
157
|
mViewManager.addLink(view, args.getInt(0), args.getInt(1), args.getString(2), args.getString(3));
|
|
155
158
|
break;
|
|
@@ -55,6 +55,7 @@ public interface EnrichedTextInputViewManagerInterface<T extends View> extends V
|
|
|
55
55
|
void toggleBlockQuote(T view);
|
|
56
56
|
void toggleOrderedList(T view);
|
|
57
57
|
void toggleUnorderedList(T view);
|
|
58
|
+
void toggleCheckboxList(T view, boolean checked);
|
|
58
59
|
void addLink(T view, int start, int end, String text, String url);
|
|
59
60
|
void addImage(T view, String uri, float width, float height);
|
|
60
61
|
void startMention(T view, String indicator);
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
namespace facebook::react {
|
|
16
16
|
|
|
17
|
-
void
|
|
17
|
+
void ReactNativeEnrichedSpec_registerComponentDescriptorsFromCodegen(
|
|
18
18
|
std::shared_ptr<const ComponentDescriptorProviderRegistry> registry) {
|
|
19
19
|
|
|
20
20
|
}
|
|
@@ -18,7 +18,7 @@ namespace facebook::react {
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
void
|
|
21
|
+
void ReactNativeEnrichedSpec_registerComponentDescriptorsFromCodegen(
|
|
22
22
|
std::shared_ptr<const ComponentDescriptorProviderRegistry> registry);
|
|
23
23
|
|
|
24
24
|
} // namespace facebook::react
|
|
@@ -14,18 +14,18 @@
|
|
|
14
14
|
namespace facebook::react {
|
|
15
15
|
|
|
16
16
|
void EnrichedTextInputViewEventEmitter::onInputFocus(OnInputFocus event) const {
|
|
17
|
-
dispatchEvent("inputFocus", [](jsi::Runtime &runtime) {
|
|
17
|
+
dispatchEvent("inputFocus", [event=std::move(event)](jsi::Runtime &runtime) {
|
|
18
18
|
auto payload = jsi::Object(runtime);
|
|
19
|
-
|
|
19
|
+
payload.setProperty(runtime, "target", event.target);
|
|
20
20
|
return payload;
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
void EnrichedTextInputViewEventEmitter::onInputBlur(OnInputBlur event) const {
|
|
26
|
-
dispatchEvent("inputBlur", [](jsi::Runtime &runtime) {
|
|
26
|
+
dispatchEvent("inputBlur", [event=std::move(event)](jsi::Runtime &runtime) {
|
|
27
27
|
auto payload = jsi::Object(runtime);
|
|
28
|
-
|
|
28
|
+
payload.setProperty(runtime, "target", event.target);
|
|
29
29
|
return payload;
|
|
30
30
|
});
|
|
31
31
|
}
|
|
@@ -178,32 +178,13 @@ void EnrichedTextInputViewEventEmitter::onChangeState(OnChangeState event) const
|
|
|
178
178
|
mention.setProperty(runtime, "isBlocking", event.mention.isBlocking);
|
|
179
179
|
payload.setProperty(runtime, "mention", mention);
|
|
180
180
|
}
|
|
181
|
-
|
|
182
|
-
|
|
181
|
+
{
|
|
182
|
+
auto checkboxList = jsi::Object(runtime);
|
|
183
|
+
checkboxList.setProperty(runtime, "isActive", event.checkboxList.isActive);
|
|
184
|
+
checkboxList.setProperty(runtime, "isConflicting", event.checkboxList.isConflicting);
|
|
185
|
+
checkboxList.setProperty(runtime, "isBlocking", event.checkboxList.isBlocking);
|
|
186
|
+
payload.setProperty(runtime, "checkboxList", checkboxList);
|
|
183
187
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
void EnrichedTextInputViewEventEmitter::onChangeStateDeprecated(OnChangeStateDeprecated event) const {
|
|
187
|
-
dispatchEvent("changeStateDeprecated", [event=std::move(event)](jsi::Runtime &runtime) {
|
|
188
|
-
auto payload = jsi::Object(runtime);
|
|
189
|
-
payload.setProperty(runtime, "isBold", event.isBold);
|
|
190
|
-
payload.setProperty(runtime, "isItalic", event.isItalic);
|
|
191
|
-
payload.setProperty(runtime, "isUnderline", event.isUnderline);
|
|
192
|
-
payload.setProperty(runtime, "isStrikeThrough", event.isStrikeThrough);
|
|
193
|
-
payload.setProperty(runtime, "isInlineCode", event.isInlineCode);
|
|
194
|
-
payload.setProperty(runtime, "isH1", event.isH1);
|
|
195
|
-
payload.setProperty(runtime, "isH2", event.isH2);
|
|
196
|
-
payload.setProperty(runtime, "isH3", event.isH3);
|
|
197
|
-
payload.setProperty(runtime, "isH4", event.isH4);
|
|
198
|
-
payload.setProperty(runtime, "isH5", event.isH5);
|
|
199
|
-
payload.setProperty(runtime, "isH6", event.isH6);
|
|
200
|
-
payload.setProperty(runtime, "isCodeBlock", event.isCodeBlock);
|
|
201
|
-
payload.setProperty(runtime, "isBlockQuote", event.isBlockQuote);
|
|
202
|
-
payload.setProperty(runtime, "isOrderedList", event.isOrderedList);
|
|
203
|
-
payload.setProperty(runtime, "isUnorderedList", event.isUnorderedList);
|
|
204
|
-
payload.setProperty(runtime, "isLink", event.isLink);
|
|
205
|
-
payload.setProperty(runtime, "isImage", event.isImage);
|
|
206
|
-
payload.setProperty(runtime, "isMention", event.isMention);
|
|
207
188
|
return payload;
|
|
208
189
|
});
|
|
209
190
|
}
|
|
@@ -271,4 +252,25 @@ void EnrichedTextInputViewEventEmitter::onInputKeyPress(OnInputKeyPress event) c
|
|
|
271
252
|
});
|
|
272
253
|
}
|
|
273
254
|
|
|
255
|
+
|
|
256
|
+
void EnrichedTextInputViewEventEmitter::onPasteImages(OnPasteImages event) const {
|
|
257
|
+
dispatchEvent("pasteImages", [event=std::move(event)](jsi::Runtime &runtime) {
|
|
258
|
+
auto payload = jsi::Object(runtime);
|
|
259
|
+
|
|
260
|
+
auto images = jsi::Array(runtime, event.images.size());
|
|
261
|
+
size_t imagesIndex = 0;
|
|
262
|
+
for (auto imagesValue : event.images) {
|
|
263
|
+
auto imagesObject = jsi::Object(runtime);
|
|
264
|
+
imagesObject.setProperty(runtime, "uri", imagesValue.uri);
|
|
265
|
+
imagesObject.setProperty(runtime, "type", imagesValue.type);
|
|
266
|
+
imagesObject.setProperty(runtime, "width", imagesValue.width);
|
|
267
|
+
imagesObject.setProperty(runtime, "height", imagesValue.height);
|
|
268
|
+
images.setValueAtIndex(runtime, imagesIndex++, imagesObject);
|
|
269
|
+
}
|
|
270
|
+
payload.setProperty(runtime, "images", images);
|
|
271
|
+
|
|
272
|
+
return payload;
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
274
276
|
} // namespace facebook::react
|
|
@@ -18,11 +18,11 @@ class EnrichedTextInputViewEventEmitter : public ViewEventEmitter {
|
|
|
18
18
|
using ViewEventEmitter::ViewEventEmitter;
|
|
19
19
|
|
|
20
20
|
struct OnInputFocus {
|
|
21
|
-
|
|
21
|
+
int target;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
struct OnInputBlur {
|
|
25
|
-
|
|
25
|
+
int target;
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
struct OnChangeText {
|
|
@@ -141,6 +141,12 @@ class EnrichedTextInputViewEventEmitter : public ViewEventEmitter {
|
|
|
141
141
|
bool isBlocking;
|
|
142
142
|
};
|
|
143
143
|
|
|
144
|
+
struct OnChangeStateCheckboxList {
|
|
145
|
+
bool isActive;
|
|
146
|
+
bool isConflicting;
|
|
147
|
+
bool isBlocking;
|
|
148
|
+
};
|
|
149
|
+
|
|
144
150
|
struct OnChangeState {
|
|
145
151
|
OnChangeStateBold bold;
|
|
146
152
|
OnChangeStateItalic italic;
|
|
@@ -160,27 +166,7 @@ class EnrichedTextInputViewEventEmitter : public ViewEventEmitter {
|
|
|
160
166
|
OnChangeStateLink link;
|
|
161
167
|
OnChangeStateImage image;
|
|
162
168
|
OnChangeStateMention mention;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
struct OnChangeStateDeprecated {
|
|
166
|
-
bool isBold;
|
|
167
|
-
bool isItalic;
|
|
168
|
-
bool isUnderline;
|
|
169
|
-
bool isStrikeThrough;
|
|
170
|
-
bool isInlineCode;
|
|
171
|
-
bool isH1;
|
|
172
|
-
bool isH2;
|
|
173
|
-
bool isH3;
|
|
174
|
-
bool isH4;
|
|
175
|
-
bool isH5;
|
|
176
|
-
bool isH6;
|
|
177
|
-
bool isCodeBlock;
|
|
178
|
-
bool isBlockQuote;
|
|
179
|
-
bool isOrderedList;
|
|
180
|
-
bool isUnorderedList;
|
|
181
|
-
bool isLink;
|
|
182
|
-
bool isImage;
|
|
183
|
-
bool isMention;
|
|
169
|
+
OnChangeStateCheckboxList checkboxList;
|
|
184
170
|
};
|
|
185
171
|
|
|
186
172
|
struct OnLinkDetected {
|
|
@@ -215,6 +201,17 @@ class EnrichedTextInputViewEventEmitter : public ViewEventEmitter {
|
|
|
215
201
|
struct OnInputKeyPress {
|
|
216
202
|
std::string key;
|
|
217
203
|
};
|
|
204
|
+
|
|
205
|
+
struct OnPasteImagesImages {
|
|
206
|
+
std::string uri;
|
|
207
|
+
std::string type;
|
|
208
|
+
Float width;
|
|
209
|
+
Float height;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
struct OnPasteImages {
|
|
213
|
+
std::vector<OnPasteImagesImages> images;
|
|
214
|
+
};
|
|
218
215
|
void onInputFocus(OnInputFocus value) const;
|
|
219
216
|
|
|
220
217
|
void onInputBlur(OnInputBlur value) const;
|
|
@@ -225,8 +222,6 @@ class EnrichedTextInputViewEventEmitter : public ViewEventEmitter {
|
|
|
225
222
|
|
|
226
223
|
void onChangeState(OnChangeState value) const;
|
|
227
224
|
|
|
228
|
-
void onChangeStateDeprecated(OnChangeStateDeprecated value) const;
|
|
229
|
-
|
|
230
225
|
void onLinkDetected(OnLinkDetected value) const;
|
|
231
226
|
|
|
232
227
|
void onMentionDetected(OnMentionDetected value) const;
|
|
@@ -238,5 +233,7 @@ class EnrichedTextInputViewEventEmitter : public ViewEventEmitter {
|
|
|
238
233
|
void onRequestHtmlResult(OnRequestHtmlResult value) const;
|
|
239
234
|
|
|
240
235
|
void onInputKeyPress(OnInputKeyPress value) const;
|
|
236
|
+
|
|
237
|
+
void onPasteImages(OnPasteImages value) const;
|
|
241
238
|
};
|
|
242
239
|
} // namespace facebook::react
|
|
@@ -528,6 +528,57 @@ static inline folly::dynamic toDynamic(const EnrichedTextInputViewHtmlStyleUlStr
|
|
|
528
528
|
}
|
|
529
529
|
#endif
|
|
530
530
|
|
|
531
|
+
struct EnrichedTextInputViewHtmlStyleUlCheckboxStruct {
|
|
532
|
+
Float gapWidth{0.0};
|
|
533
|
+
Float boxSize{0.0};
|
|
534
|
+
Float marginLeft{0.0};
|
|
535
|
+
SharedColor boxColor{};
|
|
536
|
+
|
|
537
|
+
#ifdef RN_SERIALIZABLE_STATE
|
|
538
|
+
bool operator==(const EnrichedTextInputViewHtmlStyleUlCheckboxStruct&) const = default;
|
|
539
|
+
|
|
540
|
+
folly::dynamic toDynamic() const {
|
|
541
|
+
folly::dynamic result = folly::dynamic::object();
|
|
542
|
+
result["gapWidth"] = gapWidth;
|
|
543
|
+
result["boxSize"] = boxSize;
|
|
544
|
+
result["marginLeft"] = marginLeft;
|
|
545
|
+
result["boxColor"] = ::facebook::react::toDynamic(boxColor);
|
|
546
|
+
return result;
|
|
547
|
+
}
|
|
548
|
+
#endif
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, EnrichedTextInputViewHtmlStyleUlCheckboxStruct &result) {
|
|
552
|
+
auto map = (std::unordered_map<std::string, RawValue>)value;
|
|
553
|
+
|
|
554
|
+
auto tmp_gapWidth = map.find("gapWidth");
|
|
555
|
+
if (tmp_gapWidth != map.end()) {
|
|
556
|
+
fromRawValue(context, tmp_gapWidth->second, result.gapWidth);
|
|
557
|
+
}
|
|
558
|
+
auto tmp_boxSize = map.find("boxSize");
|
|
559
|
+
if (tmp_boxSize != map.end()) {
|
|
560
|
+
fromRawValue(context, tmp_boxSize->second, result.boxSize);
|
|
561
|
+
}
|
|
562
|
+
auto tmp_marginLeft = map.find("marginLeft");
|
|
563
|
+
if (tmp_marginLeft != map.end()) {
|
|
564
|
+
fromRawValue(context, tmp_marginLeft->second, result.marginLeft);
|
|
565
|
+
}
|
|
566
|
+
auto tmp_boxColor = map.find("boxColor");
|
|
567
|
+
if (tmp_boxColor != map.end()) {
|
|
568
|
+
fromRawValue(context, tmp_boxColor->second, result.boxColor);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
static inline std::string toString(const EnrichedTextInputViewHtmlStyleUlCheckboxStruct &value) {
|
|
573
|
+
return "[Object EnrichedTextInputViewHtmlStyleUlCheckboxStruct]";
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
#ifdef RN_SERIALIZABLE_STATE
|
|
577
|
+
static inline folly::dynamic toDynamic(const EnrichedTextInputViewHtmlStyleUlCheckboxStruct &value) {
|
|
578
|
+
return value.toDynamic();
|
|
579
|
+
}
|
|
580
|
+
#endif
|
|
581
|
+
|
|
531
582
|
struct EnrichedTextInputViewHtmlStyleStruct {
|
|
532
583
|
EnrichedTextInputViewHtmlStyleH1Struct h1{};
|
|
533
584
|
EnrichedTextInputViewHtmlStyleH2Struct h2{};
|
|
@@ -542,6 +593,7 @@ struct EnrichedTextInputViewHtmlStyleStruct {
|
|
|
542
593
|
folly::dynamic mention{};
|
|
543
594
|
EnrichedTextInputViewHtmlStyleOlStruct ol{};
|
|
544
595
|
EnrichedTextInputViewHtmlStyleUlStruct ul{};
|
|
596
|
+
EnrichedTextInputViewHtmlStyleUlCheckboxStruct ulCheckbox{};
|
|
545
597
|
|
|
546
598
|
#ifdef RN_SERIALIZABLE_STATE
|
|
547
599
|
bool operator==(const EnrichedTextInputViewHtmlStyleStruct&) const = default;
|
|
@@ -561,6 +613,7 @@ struct EnrichedTextInputViewHtmlStyleStruct {
|
|
|
561
613
|
result["mention"] = mention;
|
|
562
614
|
result["ol"] = ::facebook::react::toDynamic(ol);
|
|
563
615
|
result["ul"] = ::facebook::react::toDynamic(ul);
|
|
616
|
+
result["ulCheckbox"] = ::facebook::react::toDynamic(ulCheckbox);
|
|
564
617
|
return result;
|
|
565
618
|
}
|
|
566
619
|
#endif
|
|
@@ -621,6 +674,10 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu
|
|
|
621
674
|
if (tmp_ul != map.end()) {
|
|
622
675
|
fromRawValue(context, tmp_ul->second, result.ul);
|
|
623
676
|
}
|
|
677
|
+
auto tmp_ulCheckbox = map.find("ulCheckbox");
|
|
678
|
+
if (tmp_ulCheckbox != map.end()) {
|
|
679
|
+
fromRawValue(context, tmp_ulCheckbox->second, result.ulCheckbox);
|
|
680
|
+
}
|
|
624
681
|
}
|
|
625
682
|
|
|
626
683
|
static inline std::string toString(const EnrichedTextInputViewHtmlStyleStruct &value) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
ReactNativeEnriched_kotlinVersion=2.0.21
|
|
2
|
+
ReactNativeEnriched_minSdkVersion=24
|
|
3
|
+
ReactNativeEnriched_targetSdkVersion=34
|
|
4
|
+
ReactNativeEnriched_compileSdkVersion=35
|
|
5
|
+
ReactNativeEnriched_ndkVersion=27.1.12297006
|
|
@@ -4,10 +4,11 @@ import com.facebook.react.ReactPackage
|
|
|
4
4
|
import com.facebook.react.bridge.NativeModule
|
|
5
5
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
6
|
import com.facebook.react.uimanager.ViewManager
|
|
7
|
-
import com.swmansion.enriched.
|
|
7
|
+
import com.swmansion.enriched.common.ResourceManager
|
|
8
|
+
import com.swmansion.enriched.textinput.EnrichedTextInputViewManager
|
|
8
9
|
import java.util.ArrayList
|
|
9
10
|
|
|
10
|
-
class
|
|
11
|
+
class ReactNativeEnrichedPackage : ReactPackage {
|
|
11
12
|
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
12
13
|
ResourceManager.init(reactContext.applicationContext)
|
|
13
14
|
val viewManagers: MutableList<ViewManager<*, *>> = ArrayList()
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
package com.swmansion.enriched.
|
|
1
|
+
package com.swmansion.enriched.common
|
|
2
2
|
|
|
3
|
-
import android.annotation.SuppressLint
|
|
4
3
|
import android.content.res.Resources
|
|
5
4
|
import android.graphics.BitmapFactory
|
|
6
5
|
import android.graphics.Canvas
|
|
7
6
|
import android.graphics.Color
|
|
8
7
|
import android.graphics.ColorFilter
|
|
8
|
+
import android.graphics.ImageDecoder
|
|
9
9
|
import android.graphics.PixelFormat
|
|
10
|
+
import android.graphics.drawable.AnimatedImageDrawable
|
|
10
11
|
import android.graphics.drawable.Drawable
|
|
12
|
+
import android.os.Build
|
|
11
13
|
import android.os.Handler
|
|
12
14
|
import android.os.Looper
|
|
13
15
|
import android.util.Log
|
|
14
|
-
import androidx.core.content.res.ResourcesCompat
|
|
15
|
-
import androidx.core.graphics.drawable.DrawableCompat
|
|
16
16
|
import androidx.core.graphics.drawable.toDrawable
|
|
17
17
|
import com.swmansion.enriched.R
|
|
18
18
|
import java.net.URL
|
|
19
|
+
import java.nio.ByteBuffer
|
|
19
20
|
import java.util.concurrent.Executors
|
|
20
21
|
|
|
21
22
|
class AsyncDrawable(
|
|
@@ -37,13 +38,12 @@ class AsyncDrawable(
|
|
|
37
38
|
try {
|
|
38
39
|
isLoaded = false
|
|
39
40
|
val inputStream = URL(url).openStream()
|
|
40
|
-
val
|
|
41
|
+
val bytes = inputStream.readBytes()
|
|
42
|
+
val d = prepareDrawable(bytes)
|
|
41
43
|
|
|
42
44
|
// Switch to Main Thread to update UI
|
|
43
45
|
mainHandler.post {
|
|
44
|
-
if (
|
|
45
|
-
val d = bitmap.toDrawable(Resources.getSystem())
|
|
46
|
-
|
|
46
|
+
if (d != null) {
|
|
47
47
|
d.bounds = bounds
|
|
48
48
|
internalDrawable = d
|
|
49
49
|
} else {
|
|
@@ -61,6 +61,38 @@ class AsyncDrawable(
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
private fun prepareDrawable(bytes: ByteArray): Drawable? {
|
|
65
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
66
|
+
try {
|
|
67
|
+
val buffer = ByteBuffer.wrap(bytes)
|
|
68
|
+
val source = ImageDecoder.createSource(buffer)
|
|
69
|
+
|
|
70
|
+
val drawable =
|
|
71
|
+
ImageDecoder.decodeDrawable(source) { decoder, _, _ ->
|
|
72
|
+
decoder.setTargetSize(bounds.width(), bounds.height())
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (drawable is AnimatedImageDrawable) {
|
|
76
|
+
drawable.setBounds(0, 0, drawable.intrinsicWidth, drawable.intrinsicHeight)
|
|
77
|
+
drawable.repeatCount = AnimatedImageDrawable.REPEAT_INFINITE
|
|
78
|
+
drawable.start()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return drawable
|
|
82
|
+
} catch (e: Exception) {
|
|
83
|
+
Log.w("AsyncDrawable", "ImageDecoder failed, falling back to Bitmap", e)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Fallback to bitmap if ImageDecoder fails
|
|
88
|
+
return try {
|
|
89
|
+
val bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
|
|
90
|
+
bitmap?.toDrawable(Resources.getSystem())
|
|
91
|
+
} catch (_: Exception) {
|
|
92
|
+
null
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
64
96
|
private fun loadPlaceholderImage() {
|
|
65
97
|
internalDrawable = ResourceManager.getDrawableResource(R.drawable.broken_image)
|
|
66
98
|
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
package com.swmansion.enriched.common
|
|
2
|
+
|
|
3
|
+
import android.graphics.Canvas
|
|
4
|
+
import android.graphics.ColorFilter
|
|
5
|
+
import android.graphics.Paint
|
|
6
|
+
import android.graphics.Path
|
|
7
|
+
import android.graphics.PixelFormat
|
|
8
|
+
import android.graphics.PorterDuff
|
|
9
|
+
import android.graphics.PorterDuffXfermode
|
|
10
|
+
import android.graphics.drawable.Drawable
|
|
11
|
+
|
|
12
|
+
class CheckboxDrawable(
|
|
13
|
+
private val size: Int,
|
|
14
|
+
private var color: Int,
|
|
15
|
+
private var isChecked: Boolean,
|
|
16
|
+
) : Drawable() {
|
|
17
|
+
private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
|
|
18
|
+
private val path = Path()
|
|
19
|
+
|
|
20
|
+
fun update(checked: Boolean) {
|
|
21
|
+
this.isChecked = checked
|
|
22
|
+
invalidateSelf()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
override fun draw(canvas: Canvas) {
|
|
26
|
+
val saveCount = canvas.saveLayer(0f, 0f, size.toFloat(), size.toFloat(), null)
|
|
27
|
+
|
|
28
|
+
paint.color = color
|
|
29
|
+
paint.style = Paint.Style.FILL
|
|
30
|
+
|
|
31
|
+
// Full square background with transparent checkmark
|
|
32
|
+
if (isChecked) {
|
|
33
|
+
val cornerRadius = size * 0.15f
|
|
34
|
+
canvas.drawRoundRect(0f, 0f, size.toFloat(), size.toFloat(), cornerRadius, cornerRadius, paint)
|
|
35
|
+
|
|
36
|
+
paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.XOR)
|
|
37
|
+
paint.strokeWidth = size * 0.15f
|
|
38
|
+
paint.style = Paint.Style.STROKE
|
|
39
|
+
paint.strokeCap = Paint.Cap.ROUND
|
|
40
|
+
paint.strokeJoin = Paint.Join.ROUND
|
|
41
|
+
|
|
42
|
+
path.reset()
|
|
43
|
+
path.moveTo(size * 0.25f, size * 0.5f)
|
|
44
|
+
path.lineTo(size * 0.45f, size * 0.7f)
|
|
45
|
+
path.lineTo(size * 0.75f, size * 0.3f)
|
|
46
|
+
canvas.drawPath(path, paint)
|
|
47
|
+
|
|
48
|
+
paint.xfermode = null
|
|
49
|
+
canvas.restoreToCount(saveCount)
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Border only square for unchecked state
|
|
54
|
+
paint.style = Paint.Style.STROKE
|
|
55
|
+
paint.strokeWidth = size * 0.1f
|
|
56
|
+
val margin = paint.strokeWidth / 2f
|
|
57
|
+
val cornerRadius = size * 0.15f
|
|
58
|
+
canvas.drawRoundRect(
|
|
59
|
+
margin,
|
|
60
|
+
margin,
|
|
61
|
+
size - margin,
|
|
62
|
+
size - margin,
|
|
63
|
+
cornerRadius,
|
|
64
|
+
cornerRadius,
|
|
65
|
+
paint,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
canvas.restoreToCount(saveCount)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
override fun setAlpha(alpha: Int) {
|
|
72
|
+
paint.alpha = alpha
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
override fun setColorFilter(colorFilter: ColorFilter?) {
|
|
76
|
+
paint.colorFilter = colorFilter
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@Deprecated("Deprecated in Java")
|
|
80
|
+
override fun getOpacity(): Int = PixelFormat.TRANSLUCENT
|
|
81
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
package com.swmansion.enriched.common
|
|
2
|
+
|
|
3
|
+
interface EnrichedStyle {
|
|
4
|
+
// Headers
|
|
5
|
+
val h1FontSize: Int
|
|
6
|
+
val h1Bold: Boolean
|
|
7
|
+
val h2FontSize: Int
|
|
8
|
+
val h2Bold: Boolean
|
|
9
|
+
val h3FontSize: Int
|
|
10
|
+
val h3Bold: Boolean
|
|
11
|
+
val h4FontSize: Int
|
|
12
|
+
val h4Bold: Boolean
|
|
13
|
+
val h5FontSize: Int
|
|
14
|
+
val h5Bold: Boolean
|
|
15
|
+
val h6FontSize: Int
|
|
16
|
+
val h6Bold: Boolean
|
|
17
|
+
|
|
18
|
+
// Blockquote
|
|
19
|
+
val blockquoteColor: Int?
|
|
20
|
+
val blockquoteBorderColor: Int
|
|
21
|
+
val blockquoteStripeWidth: Int
|
|
22
|
+
val blockquoteGapWidth: Int
|
|
23
|
+
|
|
24
|
+
// Ordered Lists
|
|
25
|
+
val olGapWidth: Int
|
|
26
|
+
val olMarginLeft: Int
|
|
27
|
+
val olMarkerFontWeight: Int?
|
|
28
|
+
val olMarkerColor: Int?
|
|
29
|
+
|
|
30
|
+
// Unordered Lists
|
|
31
|
+
val ulGapWidth: Int
|
|
32
|
+
val ulMarginLeft: Int
|
|
33
|
+
val ulBulletSize: Int
|
|
34
|
+
val ulBulletColor: Int
|
|
35
|
+
|
|
36
|
+
// Checkbox list
|
|
37
|
+
val ulCheckboxBoxSize: Int
|
|
38
|
+
val ulCheckboxGapWidth: Int
|
|
39
|
+
val ulCheckboxMarginLeft: Int
|
|
40
|
+
val ulCheckboxBoxColor: Int
|
|
41
|
+
|
|
42
|
+
// Links
|
|
43
|
+
val aColor: Int
|
|
44
|
+
val aUnderline: Boolean
|
|
45
|
+
|
|
46
|
+
// Code Blocks
|
|
47
|
+
val codeBlockColor: Int
|
|
48
|
+
val codeBlockBackgroundColor: Int
|
|
49
|
+
val codeBlockRadius: Float
|
|
50
|
+
|
|
51
|
+
// Inline Code
|
|
52
|
+
val inlineCodeColor: Int
|
|
53
|
+
val inlineCodeBackgroundColor: Int
|
|
54
|
+
|
|
55
|
+
// Mentions
|
|
56
|
+
val mentionsStyle: Map<String, MentionStyle>
|
|
57
|
+
}
|