react-native-marcus 0.1.1 → 0.2.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 +220 -63
- package/RNMarcus.podspec +6 -0
- package/android/src/main/java/app/getbullet/marcus/MarcusPackage.kt +2 -1
- package/android/src/main/java/app/getbullet/marcus/MarcusTextDecoratorView.kt +168 -0
- package/android/src/main/java/app/getbullet/marcus/MarcusTextDecoratorViewManager.kt +38 -0
- package/android/src/main/java/app/getbullet/marcus/MarcusTextDecoratorViewManagerSpec.kt +19 -0
- package/android/src/main/java/app/getbullet/marcus/MarcusTextInputDecoratorView.kt +23 -1
- package/android/src/main/java/app/getbullet/marcus/MarkdownBackgroundPainter.kt +147 -0
- package/android/src/main/java/app/getbullet/marcus/MarkdownBackgroundPass.kt +19 -0
- package/android/src/main/java/app/getbullet/marcus/MarkdownCopy.kt +87 -0
- package/android/src/main/java/app/getbullet/marcus/MarkdownFormatter.kt +652 -113
- package/android/src/main/java/app/getbullet/marcus/MarkdownRanges.kt +47 -0
- package/android/src/main/java/app/getbullet/marcus/MarkdownStyle.kt +140 -61
- package/android/src/main/java/app/getbullet/marcus/MarkdownUtils.kt +37 -7
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownAbsoluteLineHeightSpan.kt +48 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBackgroundSpan.kt +102 -48
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBlockIndentSpan.kt +22 -4
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBulletSpan.kt +78 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownCodeBlockSpan.kt +177 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownFontStyleSpan.kt +32 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownFontWeightSpan.kt +34 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownGapSpan.kt +24 -11
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownLetterSpacingSpan.kt +32 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownTextShadowSpan.kt +32 -0
- package/android/src/main/new_arch/CMakeLists.txt +17 -0
- package/android/src/main/new_arch/RNMarcusSpec.h +1 -0
- package/android/src/main/new_arch/react/renderer/components/RNMarcusSpec/MarcusTextDecoratorShadowNode.cpp +235 -0
- package/android/src/main/new_arch/react/renderer/components/RNMarcusSpec/MarcusTextDecoratorShadowNode.h +62 -0
- package/android/src/reactNativeVersionPatch/CustomMountingManager/81/app/getbullet/marcus/CustomFabricUIManager.java +22 -3
- package/android/src/reactNativeVersionPatch/CustomMountingManager/latest/app/getbullet/marcus/CustomFabricUIManager.java +22 -3
- package/android/src/test/java/app/getbullet/marcus/MarkdownCopyTest.kt +69 -0
- package/android/src/test/java/app/getbullet/marcus/MarkdownFormatterTest.kt +170 -25
- package/android/src/test/java/app/getbullet/marcus/RenderModel.kt +22 -5
- package/android/src/test/java/app/getbullet/marcus/spans/MarkdownCodeBlockSpanTest.kt +91 -0
- package/android/src/test/resources/render-model.txt +221 -16
- package/apple/MarcusSwizzle.h +25 -0
- package/apple/MarcusTextDecoratorComponentView.h +22 -0
- package/apple/MarcusTextDecoratorComponentView.mm +72 -0
- package/apple/MarcusTextDecoratorShadowNode.h +62 -0
- package/apple/MarcusTextDecoratorShadowNode.mm +192 -0
- package/apple/MarcusTextDecoratorViewManager.h +4 -0
- package/apple/MarcusTextDecoratorViewManager.mm +11 -0
- package/apple/MarcusTextInputDecoratorComponentView.mm +1 -1
- package/apple/MarcusTextInputDecoratorShadowNode.mm +1 -1
- package/apple/MarcusTextLayoutManager.h +40 -0
- package/apple/MarcusTextLayoutManager.mm +173 -0
- package/apple/MarkdownAttributes.h +23 -2
- package/apple/MarkdownAttributes.m +6 -0
- package/apple/MarkdownCopy.swift +63 -0
- package/apple/MarkdownDecorator.swift +2 -2
- package/apple/MarkdownFormatter+React.swift +23 -0
- package/apple/MarkdownFormatter.swift +869 -148
- package/apple/MarkdownParagraphLayoutManager.swift +455 -0
- package/apple/MarkdownSwiftInterop.h +0 -1
- package/apple/MarkdownTextBackground.swift +59 -1
- package/apple/MarkdownTextFieldObserver.swift +2 -2
- package/apple/MarkdownTextLayoutFragment.swift +159 -33
- package/apple/MarkdownTextLayoutManagerDelegate.swift +67 -3
- package/apple/MarkdownTextStorageDelegate.swift +2 -2
- package/apple/MarkdownTextViewObserver.swift +2 -2
- package/apple/MarkdownUtils.swift +38 -0
- package/apple/MarkdownWritingDirection.swift +132 -0
- package/apple/RCTMarcusStyle+Codegen.h +115 -9
- package/apple/RCTMarcusStyle.h +128 -31
- package/apple/RCTMarcusStyle.m +48 -0
- package/apple/RCTParagraphComponentView+Marcus.h +17 -0
- package/apple/RCTParagraphComponentView+Marcus.mm +38 -0
- package/apple/RCTTextInputComponentView+Marcus.mm +1 -25
- package/cpp/react/renderer/components/RNMarcusSpec/MarcusTextDecoratorState.h +37 -0
- package/cpp/react/renderer/components/RNMarcusSpec/MarcusTextDecoratorViewComponentDescriptor.h +17 -0
- package/lib/commonjs/MarcusTextDecoratorViewNativeComponent.ts +199 -0
- package/lib/commonjs/MarcusTextInputDecoratorViewNativeComponent.ts +145 -58
- package/lib/commonjs/MarkdownText.js +330 -0
- package/lib/commonjs/MarkdownText.js.map +1 -0
- package/lib/commonjs/MarkdownText.web.js +529 -0
- package/lib/commonjs/MarkdownText.web.js.map +1 -0
- package/lib/commonjs/MarkdownTextInput.js +22 -27
- package/lib/commonjs/MarkdownTextInput.js.map +1 -1
- package/lib/commonjs/MarkdownTextInput.web.js +12 -7
- package/lib/commonjs/MarkdownTextInput.web.js.map +1 -1
- package/lib/commonjs/atomUtils.js +112 -0
- package/lib/commonjs/atomUtils.js.map +1 -0
- package/lib/commonjs/childrenUtils.js +36 -0
- package/lib/commonjs/childrenUtils.js.map +1 -0
- package/lib/commonjs/index.js +8 -7
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/math/environment.js +69 -0
- package/lib/commonjs/math/environment.js.map +1 -0
- package/lib/commonjs/math/index.js +61 -0
- package/lib/commonjs/math/index.js.map +1 -0
- package/lib/commonjs/math/mathjax.js +548 -0
- package/lib/commonjs/math/mathjax.js.map +1 -0
- package/lib/commonjs/metro.js +172 -0
- package/lib/commonjs/metro.js.map +1 -0
- package/lib/commonjs/parser/index.d.ts +3 -0
- package/lib/commonjs/parser/index.js +450 -42
- package/lib/commonjs/parser/index.js.map +4 -4
- package/lib/commonjs/stripUtils.js +743 -0
- package/lib/commonjs/stripUtils.js.map +1 -0
- package/lib/commonjs/styleUtils.js +194 -23
- package/lib/commonjs/styleUtils.js.map +1 -1
- package/lib/commonjs/web/MarkdownElements.css +67 -0
- package/lib/commonjs/web/MarkdownTextInput.css +9 -7
- package/lib/commonjs/web/utils/blockLayout.js +95 -7
- package/lib/commonjs/web/utils/blockLayout.js.map +1 -1
- package/lib/commonjs/web/utils/blockUtils.js +327 -54
- package/lib/commonjs/web/utils/blockUtils.js.map +1 -1
- package/lib/commonjs/web/utils/elementUtils.js +80 -0
- package/lib/commonjs/web/utils/elementUtils.js.map +1 -0
- package/lib/commonjs/web/utils/parserUtils.js +84 -28
- package/lib/commonjs/web/utils/parserUtils.js.map +1 -1
- package/lib/commonjs/web/utils/treeUtils.js +6 -0
- package/lib/commonjs/web/utils/treeUtils.js.map +1 -1
- package/lib/commonjs/web/utils/webStyleUtils.js +25 -5
- package/lib/commonjs/web/utils/webStyleUtils.js.map +1 -1
- package/lib/module/MarcusTextDecoratorViewNativeComponent.ts +199 -0
- package/lib/module/MarcusTextInputDecoratorViewNativeComponent.ts +145 -58
- package/lib/module/MarkdownText.js +325 -0
- package/lib/module/MarkdownText.js.map +1 -0
- package/lib/module/MarkdownText.web.js +524 -0
- package/lib/module/MarkdownText.web.js.map +1 -0
- package/lib/module/MarkdownTextInput.js +24 -29
- package/lib/module/MarkdownTextInput.js.map +1 -1
- package/lib/module/MarkdownTextInput.web.js +12 -7
- package/lib/module/MarkdownTextInput.web.js.map +1 -1
- package/lib/module/atomUtils.js +106 -0
- package/lib/module/atomUtils.js.map +1 -0
- package/lib/module/childrenUtils.js +33 -0
- package/lib/module/childrenUtils.js.map +1 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/math/environment.js +67 -0
- package/lib/module/math/environment.js.map +1 -0
- package/lib/module/math/index.js +56 -0
- package/lib/module/math/index.js.map +1 -0
- package/lib/module/math/mathjax.js +541 -0
- package/lib/module/math/mathjax.js.map +1 -0
- package/lib/module/metro.js +169 -0
- package/lib/module/metro.js.map +1 -0
- package/lib/module/parser/index.d.ts +3 -0
- package/lib/module/parser/index.js +450 -42
- package/lib/module/parser/index.js.map +4 -4
- package/lib/module/stripUtils.js +739 -0
- package/lib/module/stripUtils.js.map +1 -0
- package/lib/module/styleUtils.js +196 -25
- package/lib/module/styleUtils.js.map +1 -1
- package/lib/module/web/MarkdownElements.css +67 -0
- package/lib/module/web/MarkdownTextInput.css +9 -7
- package/lib/module/web/utils/blockLayout.js +94 -8
- package/lib/module/web/utils/blockLayout.js.map +1 -1
- package/lib/module/web/utils/blockUtils.js +328 -56
- package/lib/module/web/utils/blockUtils.js.map +1 -1
- package/lib/module/web/utils/elementUtils.js +75 -0
- package/lib/module/web/utils/elementUtils.js.map +1 -0
- package/lib/module/web/utils/parserUtils.js +86 -30
- package/lib/module/web/utils/parserUtils.js.map +1 -1
- package/lib/module/web/utils/treeUtils.js +6 -0
- package/lib/module/web/utils/treeUtils.js.map +1 -1
- package/lib/module/web/utils/webStyleUtils.js +25 -5
- package/lib/module/web/utils/webStyleUtils.js.map +1 -1
- package/lib/typescript/commonjs/e2e/links.test.d.ts +2 -0
- package/lib/typescript/commonjs/e2e/links.test.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/MarcusTextDecoratorViewNativeComponent.d.ts +93 -0
- package/lib/typescript/commonjs/src/MarcusTextDecoratorViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/MarcusTextInputDecoratorViewNativeComponent.d.ts +64 -51
- package/lib/typescript/commonjs/src/MarcusTextInputDecoratorViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/MarkdownText.d.ts +127 -0
- package/lib/typescript/commonjs/src/MarkdownText.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/MarkdownText.web.d.ts +126 -0
- package/lib/typescript/commonjs/src/MarkdownText.web.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/MarkdownTextInput.d.ts +23 -1
- package/lib/typescript/commonjs/src/MarkdownTextInput.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/MarkdownTextInput.web.d.ts +26 -4
- package/lib/typescript/commonjs/src/MarkdownTextInput.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/atomUtils.d.ts +58 -0
- package/lib/typescript/commonjs/src/atomUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/childrenUtils.d.ts +12 -0
- package/lib/typescript/commonjs/src/childrenUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/commonTypes.d.ts +39 -3
- package/lib/typescript/commonjs/src/commonTypes.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/index.d.ts +2 -1
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/math/environment.d.ts +7 -0
- package/lib/typescript/commonjs/src/math/environment.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/math/index.d.ts +64 -0
- package/lib/typescript/commonjs/src/math/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/math/mathjax.d.ts +63 -0
- package/lib/typescript/commonjs/src/math/mathjax.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/metro.d.ts +59 -0
- package/lib/typescript/commonjs/src/metro.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/parser/index.d.ts +3 -3
- package/lib/typescript/commonjs/src/parser/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/parser/micromark-extension-mentions.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/rangeUtils.d.ts +1 -1
- package/lib/typescript/commonjs/src/stripUtils.d.ts +108 -0
- package/lib/typescript/commonjs/src/stripUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/styleUtils.d.ts +62 -4
- package/lib/typescript/commonjs/src/styleUtils.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/web/utils/blockLayout.d.ts +32 -4
- package/lib/typescript/commonjs/src/web/utils/blockLayout.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/web/utils/blockUtils.d.ts +20 -8
- package/lib/typescript/commonjs/src/web/utils/blockUtils.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/web/utils/elementUtils.d.ts +37 -0
- package/lib/typescript/commonjs/src/web/utils/elementUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/web/utils/parserUtils.d.ts +5 -5
- package/lib/typescript/commonjs/src/web/utils/parserUtils.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/web/utils/treeUtils.d.ts +6 -1
- package/lib/typescript/commonjs/src/web/utils/treeUtils.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/web/utils/webStyleUtils.d.ts +2 -2
- package/lib/typescript/commonjs/src/web/utils/webStyleUtils.d.ts.map +1 -1
- package/lib/typescript/module/e2e/links.test.d.ts +2 -0
- package/lib/typescript/module/e2e/links.test.d.ts.map +1 -0
- package/lib/typescript/module/src/MarcusTextDecoratorViewNativeComponent.d.ts +93 -0
- package/lib/typescript/module/src/MarcusTextDecoratorViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/MarcusTextInputDecoratorViewNativeComponent.d.ts +64 -51
- package/lib/typescript/module/src/MarcusTextInputDecoratorViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/module/src/MarkdownText.d.ts +127 -0
- package/lib/typescript/module/src/MarkdownText.d.ts.map +1 -0
- package/lib/typescript/module/src/MarkdownText.web.d.ts +126 -0
- package/lib/typescript/module/src/MarkdownText.web.d.ts.map +1 -0
- package/lib/typescript/module/src/MarkdownTextInput.d.ts +23 -1
- package/lib/typescript/module/src/MarkdownTextInput.d.ts.map +1 -1
- package/lib/typescript/module/src/MarkdownTextInput.web.d.ts +26 -4
- package/lib/typescript/module/src/MarkdownTextInput.web.d.ts.map +1 -1
- package/lib/typescript/module/src/atomUtils.d.ts +58 -0
- package/lib/typescript/module/src/atomUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/childrenUtils.d.ts +12 -0
- package/lib/typescript/module/src/childrenUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/commonTypes.d.ts +39 -3
- package/lib/typescript/module/src/commonTypes.d.ts.map +1 -1
- package/lib/typescript/module/src/index.d.ts +2 -1
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/math/environment.d.ts +7 -0
- package/lib/typescript/module/src/math/environment.d.ts.map +1 -0
- package/lib/typescript/module/src/math/index.d.ts +64 -0
- package/lib/typescript/module/src/math/index.d.ts.map +1 -0
- package/lib/typescript/module/src/math/mathjax.d.ts +63 -0
- package/lib/typescript/module/src/math/mathjax.d.ts.map +1 -0
- package/lib/typescript/module/src/metro.d.ts +59 -0
- package/lib/typescript/module/src/metro.d.ts.map +1 -0
- package/lib/typescript/module/src/parser/index.d.ts +3 -3
- package/lib/typescript/module/src/parser/index.d.ts.map +1 -1
- package/lib/typescript/module/src/parser/micromark-extension-mentions.d.ts.map +1 -1
- package/lib/typescript/module/src/rangeUtils.d.ts +1 -1
- package/lib/typescript/module/src/stripUtils.d.ts +108 -0
- package/lib/typescript/module/src/stripUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/styleUtils.d.ts +62 -4
- package/lib/typescript/module/src/styleUtils.d.ts.map +1 -1
- package/lib/typescript/module/src/web/utils/blockLayout.d.ts +32 -4
- package/lib/typescript/module/src/web/utils/blockLayout.d.ts.map +1 -1
- package/lib/typescript/module/src/web/utils/blockUtils.d.ts +20 -8
- package/lib/typescript/module/src/web/utils/blockUtils.d.ts.map +1 -1
- package/lib/typescript/module/src/web/utils/elementUtils.d.ts +37 -0
- package/lib/typescript/module/src/web/utils/elementUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/web/utils/parserUtils.d.ts +5 -5
- package/lib/typescript/module/src/web/utils/parserUtils.d.ts.map +1 -1
- package/lib/typescript/module/src/web/utils/treeUtils.d.ts +6 -1
- package/lib/typescript/module/src/web/utils/treeUtils.d.ts.map +1 -1
- package/lib/typescript/module/src/web/utils/webStyleUtils.d.ts +2 -2
- package/lib/typescript/module/src/web/utils/webStyleUtils.d.ts.map +1 -1
- package/package.json +29 -2
- package/react-native.config.js +8 -1
- package/src/MarcusTextDecoratorViewNativeComponent.ts +199 -0
- package/src/MarcusTextInputDecoratorViewNativeComponent.ts +145 -58
- package/src/MarkdownText.tsx +472 -0
- package/src/MarkdownText.web.tsx +668 -0
- package/src/MarkdownTextInput.tsx +42 -38
- package/src/MarkdownTextInput.web.tsx +36 -13
- package/src/atomUtils.ts +112 -0
- package/src/childrenUtils.ts +39 -0
- package/src/commonTypes.ts +69 -9
- package/src/index.tsx +2 -1
- package/src/math/environment.ts +68 -0
- package/src/math/index.ts +78 -0
- package/src/math/mathjax.ts +604 -0
- package/src/metro.ts +238 -0
- package/src/parser/index.ts +175 -10
- package/src/parser/micromark-extension-mentions.ts +104 -11
- package/src/stripUtils.ts +919 -0
- package/src/styleUtils.ts +290 -26
- package/src/web/MarkdownElements.css +67 -0
- package/src/web/MarkdownTextInput.css +9 -7
- package/src/web/utils/blockLayout.ts +124 -14
- package/src/web/utils/blockUtils.ts +365 -59
- package/src/web/utils/elementUtils.ts +87 -0
- package/src/web/utils/parserUtils.ts +119 -31
- package/src/web/utils/treeUtils.ts +6 -1
- package/src/web/utils/webStyleUtils.ts +32 -8
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBackgroundColorSpan.kt +0 -6
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBoldSpan.kt +0 -6
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownItalicSpan.kt +0 -6
- package/apple/RCTMarcusStyle+Codegen.mm +0 -64
- package/apple/RCTMarcusUtils.h +0 -26
- package/apple/RCTMarcusUtils.mm +0 -26
|
@@ -1,18 +1,124 @@
|
|
|
1
1
|
#import <RNMarcus/RCTMarcusStyle.h>
|
|
2
2
|
|
|
3
|
-
#import <
|
|
3
|
+
#import <React/RCTConversions.h>
|
|
4
4
|
|
|
5
5
|
NS_ASSUME_NONNULL_BEGIN
|
|
6
6
|
|
|
7
|
-
// Conversion from the codegen props struct lives in a separate
|
|
8
|
-
// `RCTMarcusStyle.h` itself stays free of C++. Only the component
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
|
|
7
|
+
// Conversion from the codegen props struct lives in a separate header so that
|
|
8
|
+
// `RCTMarcusStyle.h` itself stays free of C++. Only the component views and the
|
|
9
|
+
// shadow nodes need this one; everything downstream can import the plain header.
|
|
10
|
+
//
|
|
11
|
+
// These are templates rather than initialisers because codegen emits a separate
|
|
12
|
+
// struct type per prop path even when the shape is identical: `code` and `pre`
|
|
13
|
+
// are written as one interface in TypeScript and arrive as two unrelated C++
|
|
14
|
+
// types, and so do the twelve copies of the text style. The shape is held
|
|
15
|
+
// together on the JavaScript side instead, by the assignability assertion in
|
|
16
|
+
// `MarcusTextDecoratorViewNativeComponent.ts`.
|
|
12
17
|
|
|
13
|
-
|
|
14
|
-
|
|
18
|
+
// A colour that was never written is `SharedColor`'s undefined value rather than
|
|
19
|
+
// a transparent one, and the difference matters: unset means "inherit whatever
|
|
20
|
+
// the prose is drawn in", where transparent means "draw nothing".
|
|
21
|
+
static inline UIColor *_Nullable
|
|
22
|
+
RCTMarcusColor(const facebook::react::SharedColor &color) {
|
|
23
|
+
return color ? RCTUIColorFromSharedColor(color) : nil;
|
|
24
|
+
}
|
|
15
25
|
|
|
16
|
-
|
|
26
|
+
template <typename TextStyleStruct>
|
|
27
|
+
static inline void RCTMarcusApplyTextStyle(RCTMarcusTextStyle *result,
|
|
28
|
+
const TextStyleStruct &style) {
|
|
29
|
+
result.color = RCTMarcusColor(style.color);
|
|
30
|
+
result.fontFamily = RCTNSStringFromStringNilIfEmpty(style.fontFamily);
|
|
31
|
+
result.fontSize = style.fontSize;
|
|
32
|
+
result.fontStyle = RCTNSStringFromStringNilIfEmpty(style.fontStyle);
|
|
33
|
+
result.fontWeight = RCTNSStringFromStringNilIfEmpty(style.fontWeight);
|
|
34
|
+
result.letterSpacing = style.letterSpacing;
|
|
35
|
+
result.lineHeight = style.lineHeight;
|
|
36
|
+
result.textDecorationLine =
|
|
37
|
+
RCTNSStringFromStringNilIfEmpty(style.textDecorationLine);
|
|
38
|
+
result.textDecorationColor = RCTMarcusColor(style.textDecorationColor);
|
|
39
|
+
result.textDecorationStyle =
|
|
40
|
+
RCTNSStringFromStringNilIfEmpty(style.textDecorationStyle);
|
|
41
|
+
result.textShadowColor = RCTMarcusColor(style.textShadowColor);
|
|
42
|
+
result.textShadowOffset =
|
|
43
|
+
CGSizeMake(style.textShadowOffset.width, style.textShadowOffset.height);
|
|
44
|
+
result.textShadowRadius = style.textShadowRadius;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
template <typename TextStyleStruct>
|
|
48
|
+
static inline RCTMarcusTextStyle *
|
|
49
|
+
RCTMarcusTextStyleFromStruct(const TextStyleStruct &style) {
|
|
50
|
+
RCTMarcusTextStyle *result = [RCTMarcusTextStyle new];
|
|
51
|
+
RCTMarcusApplyTextStyle(result, style);
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// The single `padding` and `margin` a style may be written with have already
|
|
56
|
+
// been resolved into the two axes by `mergeMarkdownStyleWithDefault`, so there
|
|
57
|
+
// is nothing to fall back to here.
|
|
58
|
+
template <typename BoxStyleStruct>
|
|
59
|
+
static inline RCTMarcusBoxStyle *
|
|
60
|
+
RCTMarcusBoxStyleFromStruct(const BoxStyleStruct &style) {
|
|
61
|
+
RCTMarcusBoxStyle *result = [RCTMarcusBoxStyle new];
|
|
62
|
+
RCTMarcusApplyTextStyle(result, style);
|
|
63
|
+
|
|
64
|
+
result.backgroundColor = RCTMarcusColor(style.backgroundColor);
|
|
65
|
+
result.borderColor = RCTMarcusColor(style.borderColor);
|
|
66
|
+
result.borderWidth = style.borderWidth;
|
|
67
|
+
result.borderRadius = style.borderRadius;
|
|
68
|
+
result.paddingHorizontal = style.paddingHorizontal;
|
|
69
|
+
result.paddingVertical = style.paddingVertical;
|
|
70
|
+
result.marginHorizontal = style.marginHorizontal;
|
|
71
|
+
result.marginVertical = style.marginVertical;
|
|
72
|
+
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
template <typename ListStyleStruct>
|
|
77
|
+
static inline RCTMarcusListStyle *
|
|
78
|
+
RCTMarcusListStyleFromStruct(const ListStyleStruct &style) {
|
|
79
|
+
RCTMarcusListStyle *result = [RCTMarcusListStyle new];
|
|
80
|
+
|
|
81
|
+
result.marginStart = style.marginStart;
|
|
82
|
+
result.paddingStart = style.paddingStart;
|
|
83
|
+
result.markerScale = style.markerScale;
|
|
84
|
+
result.markerPadding = style.markerPadding;
|
|
85
|
+
result.marker = RCTMarcusTextStyleFromStruct(style.marker);
|
|
86
|
+
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
template <typename MarkdownStyleStruct>
|
|
91
|
+
static inline RCTMarcusStyle *
|
|
92
|
+
RCTMarcusStyleFromStruct(const MarkdownStyleStruct &style) {
|
|
93
|
+
RCTMarcusStyle *result = [RCTMarcusStyle new];
|
|
94
|
+
|
|
95
|
+
result.syntax = RCTMarcusTextStyleFromStruct(style.syntax);
|
|
96
|
+
result.link = RCTMarcusTextStyleFromStruct(style.link);
|
|
97
|
+
result.strong = RCTMarcusTextStyleFromStruct(style.strong);
|
|
98
|
+
result.emphasis = RCTMarcusTextStyleFromStruct(style.emphasis);
|
|
99
|
+
result.strikethrough = RCTMarcusTextStyleFromStruct(style.strikethrough);
|
|
100
|
+
|
|
101
|
+
RCTMarcusApplyTextStyle(result.heading, style.heading);
|
|
102
|
+
result.heading.scale = style.heading.scale;
|
|
103
|
+
|
|
104
|
+
result.emoji.fontSize = style.emoji.fontSize;
|
|
105
|
+
result.emoji.fontFamily = RCTNSStringFromStringNilIfEmpty(style.emoji.fontFamily);
|
|
106
|
+
|
|
107
|
+
RCTMarcusApplyTextStyle(result.blockquote, style.blockquote);
|
|
108
|
+
result.blockquote.borderColor = RCTMarcusColor(style.blockquote.borderColor);
|
|
109
|
+
result.blockquote.borderWidth = style.blockquote.borderWidth;
|
|
110
|
+
result.blockquote.borderRadius = style.blockquote.borderRadius;
|
|
111
|
+
result.blockquote.marginStart = style.blockquote.marginStart;
|
|
112
|
+
result.blockquote.paddingStart = style.blockquote.paddingStart;
|
|
113
|
+
|
|
114
|
+
result.orderedList = RCTMarcusListStyleFromStruct(style.orderedList);
|
|
115
|
+
result.unorderedList = RCTMarcusListStyleFromStruct(style.unorderedList);
|
|
116
|
+
|
|
117
|
+
result.code = RCTMarcusBoxStyleFromStruct(style.code);
|
|
118
|
+
result.pre = RCTMarcusBoxStyleFromStruct(style.pre);
|
|
119
|
+
result.mention = RCTMarcusBoxStyleFromStruct(style.mention);
|
|
120
|
+
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
17
123
|
|
|
18
124
|
NS_ASSUME_NONNULL_END
|
package/apple/RCTMarcusStyle.h
CHANGED
|
@@ -2,39 +2,136 @@
|
|
|
2
2
|
|
|
3
3
|
NS_ASSUME_NONNULL_BEGIN
|
|
4
4
|
|
|
5
|
+
/// The text attributes one styled run can carry: the subset of React Native's
|
|
6
|
+
/// `TextStyle` that survives as an attribute on an attributed string.
|
|
7
|
+
///
|
|
8
|
+
/// Everything is optional and everything unset is inherited, which is what a run
|
|
9
|
+
/// of markdown wants -- a mention that only names a colour keeps the face, the
|
|
10
|
+
/// size and the weight of the prose it sits in. "Unset" is the zero value: a nil
|
|
11
|
+
/// colour, a nil string, a zero length. Nothing is lost by that, because a
|
|
12
|
+
/// zero-length `fontSize`, `letterSpacing` or `lineHeight` would mean the same
|
|
13
|
+
/// as leaving it out.
|
|
14
|
+
///
|
|
15
|
+
/// The two font names are strings rather than an enum because they are React
|
|
16
|
+
/// Native's own spellings -- `bold`, `600`, `italic` -- and `MarkdownFonts`
|
|
17
|
+
/// resolves them through React Native's font manager rather than interpreting
|
|
18
|
+
/// them here.
|
|
19
|
+
@interface RCTMarcusTextStyle : NSObject
|
|
20
|
+
|
|
21
|
+
@property(nonatomic, nullable) UIColor *color;
|
|
22
|
+
@property(nonatomic, copy, nullable) NSString *fontFamily;
|
|
23
|
+
@property(nonatomic) CGFloat fontSize;
|
|
24
|
+
@property(nonatomic, copy, nullable) NSString *fontStyle;
|
|
25
|
+
@property(nonatomic, copy, nullable) NSString *fontWeight;
|
|
26
|
+
@property(nonatomic) CGFloat letterSpacing;
|
|
27
|
+
/// Set on the paragraph, so a range covering part of a line raises all of it.
|
|
28
|
+
@property(nonatomic) CGFloat lineHeight;
|
|
29
|
+
@property(nonatomic, copy, nullable) NSString *textDecorationLine;
|
|
30
|
+
@property(nonatomic, nullable) UIColor *textDecorationColor;
|
|
31
|
+
@property(nonatomic, copy, nullable) NSString *textDecorationStyle;
|
|
32
|
+
@property(nonatomic, nullable) UIColor *textShadowColor;
|
|
33
|
+
@property(nonatomic) CGSize textShadowOffset;
|
|
34
|
+
@property(nonatomic) CGFloat textShadowRadius;
|
|
35
|
+
|
|
36
|
+
@end
|
|
37
|
+
|
|
38
|
+
/// A run drawn as a box rather than as a background behind the glyphs: an inline
|
|
39
|
+
/// or fenced run of code, or a mention's pill.
|
|
40
|
+
///
|
|
41
|
+
/// What the room holds open differs, because a block owns its lines and a run
|
|
42
|
+
/// shares one. A block's padding and margin are held open on the leading edge
|
|
43
|
+
/// and vertically, and a line long enough to wrap reaches the padding on the
|
|
44
|
+
/// trailing edge rather than stopping in front of it: neither platform can
|
|
45
|
+
/// reserve a trailing indent per paragraph. An inline run holds its padding and
|
|
46
|
+
/// margin open on both sides, by widening the characters it starts and ends
|
|
47
|
+
/// with, and grows into the line's own spacing above and below rather than
|
|
48
|
+
/// pushing the lines apart.
|
|
49
|
+
///
|
|
50
|
+
/// Only the per-axis lengths are here. A style may be written with a single
|
|
51
|
+
/// `padding` or `margin` covering both axes; `mergeMarkdownStyleWithDefault`
|
|
52
|
+
/// resolves that into the two before the style is ever sent, so that a length of
|
|
53
|
+
/// zero here means zero rather than "unset".
|
|
54
|
+
@interface RCTMarcusBoxStyle : RCTMarcusTextStyle
|
|
55
|
+
|
|
56
|
+
@property(nonatomic, nullable) UIColor *backgroundColor;
|
|
57
|
+
@property(nonatomic, nullable) UIColor *borderColor;
|
|
58
|
+
@property(nonatomic) CGFloat borderWidth;
|
|
59
|
+
@property(nonatomic) CGFloat borderRadius;
|
|
60
|
+
@property(nonatomic) CGFloat paddingHorizontal;
|
|
61
|
+
@property(nonatomic) CGFloat paddingVertical;
|
|
62
|
+
@property(nonatomic) CGFloat marginHorizontal;
|
|
63
|
+
@property(nonatomic) CGFloat marginVertical;
|
|
64
|
+
|
|
65
|
+
@end
|
|
66
|
+
|
|
67
|
+
@interface RCTMarcusHeadingStyle : RCTMarcusTextStyle
|
|
68
|
+
|
|
69
|
+
/// Each level down multiplies the one above, so level N is
|
|
70
|
+
/// `fontSize * scale^(N - 1)`. Six levels, matching HTML.
|
|
71
|
+
@property(nonatomic) CGFloat scale;
|
|
72
|
+
|
|
73
|
+
@end
|
|
74
|
+
|
|
75
|
+
/// The bar beside a quoted block, the indent it opens, and the text inside it.
|
|
76
|
+
///
|
|
77
|
+
/// `marginStart` and `paddingStart` rather than left and right: the gutter opens
|
|
78
|
+
/// on the paragraph's leading edge, which is what `NSParagraphStyle`'s head
|
|
79
|
+
/// indent has always meant, and so the names now say what was already drawn.
|
|
80
|
+
@interface RCTMarcusBlockquoteStyle : RCTMarcusTextStyle
|
|
81
|
+
|
|
82
|
+
@property(nonatomic, nullable) UIColor *borderColor;
|
|
83
|
+
@property(nonatomic) CGFloat borderWidth;
|
|
84
|
+
/// Rounds the bar's ends. A bar whose radius is half its width is a capsule.
|
|
85
|
+
@property(nonatomic) CGFloat borderRadius;
|
|
86
|
+
@property(nonatomic) CGFloat marginStart;
|
|
87
|
+
@property(nonatomic) CGFloat paddingStart;
|
|
88
|
+
|
|
89
|
+
@end
|
|
90
|
+
|
|
91
|
+
/// Indent, and the marker that sits in the gutter it opens.
|
|
92
|
+
///
|
|
93
|
+
/// The marker is sized from the base font -- the size the wrapped `Text` renders
|
|
94
|
+
/// at -- rather than from a size of its own, so a list marks itself in
|
|
95
|
+
/// proportion to the prose it marks however that prose is sized. `marker` is
|
|
96
|
+
/// what it is drawn with, already resolved against `syntax` on the JavaScript
|
|
97
|
+
/// side, so nothing here has to know where an unset value came from.
|
|
98
|
+
@interface RCTMarcusListStyle : NSObject
|
|
99
|
+
|
|
100
|
+
@property(nonatomic) CGFloat marginStart;
|
|
101
|
+
@property(nonatomic) CGFloat paddingStart;
|
|
102
|
+
/// An ordered item's number is drawn at this fraction of the base font size; an
|
|
103
|
+
/// unordered item's bullet takes it as a diameter, as a fraction of the same.
|
|
104
|
+
@property(nonatomic) CGFloat markerScale;
|
|
105
|
+
/// Room held open either side of the marker, between the gutter and the text.
|
|
106
|
+
@property(nonatomic) CGFloat markerPadding;
|
|
107
|
+
@property(nonatomic, strong) RCTMarcusTextStyle *marker;
|
|
108
|
+
|
|
109
|
+
@end
|
|
110
|
+
|
|
111
|
+
@interface RCTMarcusEmojiStyle : NSObject
|
|
112
|
+
|
|
113
|
+
@property(nonatomic) CGFloat fontSize;
|
|
114
|
+
@property(nonatomic, copy, nullable) NSString *fontFamily;
|
|
115
|
+
|
|
116
|
+
@end
|
|
117
|
+
|
|
5
118
|
@interface RCTMarcusStyle : NSObject
|
|
6
119
|
|
|
7
|
-
@property(nonatomic)
|
|
8
|
-
@property(nonatomic)
|
|
9
|
-
@property(nonatomic)
|
|
10
|
-
@property(nonatomic)
|
|
11
|
-
@property(nonatomic)
|
|
12
|
-
@property(nonatomic)
|
|
13
|
-
@property(nonatomic)
|
|
14
|
-
@property(nonatomic)
|
|
15
|
-
@property(nonatomic)
|
|
16
|
-
@property(nonatomic)
|
|
17
|
-
@property(nonatomic)
|
|
18
|
-
@property(nonatomic)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
@property(nonatomic)
|
|
22
|
-
@property(nonatomic) CGFloat codeFontSize;
|
|
23
|
-
@property(nonatomic) UIColor *codeColor;
|
|
24
|
-
@property(nonatomic) UIColor *codeBackgroundColor;
|
|
25
|
-
@property(nonatomic) NSString *preFontFamily;
|
|
26
|
-
@property(nonatomic) CGFloat preFontSize;
|
|
27
|
-
@property(nonatomic) UIColor *preColor;
|
|
28
|
-
@property(nonatomic) UIColor *preBackgroundColor;
|
|
29
|
-
@property(nonatomic) UIColor *mentionHereColor;
|
|
30
|
-
@property(nonatomic) UIColor *mentionHereBackgroundColor;
|
|
31
|
-
@property(nonatomic) CGFloat mentionHereBorderRadius;
|
|
32
|
-
@property(nonatomic) UIColor *mentionUserColor;
|
|
33
|
-
@property(nonatomic) UIColor *mentionUserBackgroundColor;
|
|
34
|
-
@property(nonatomic) CGFloat mentionUserBorderRadius;
|
|
35
|
-
@property(nonatomic) UIColor *mentionReportColor;
|
|
36
|
-
@property(nonatomic) UIColor *mentionReportBackgroundColor;
|
|
37
|
-
@property(nonatomic) CGFloat mentionReportBorderRadius;
|
|
120
|
+
@property(nonatomic, strong) RCTMarcusTextStyle *syntax;
|
|
121
|
+
@property(nonatomic, strong) RCTMarcusTextStyle *link;
|
|
122
|
+
@property(nonatomic, strong) RCTMarcusTextStyle *strong;
|
|
123
|
+
@property(nonatomic, strong) RCTMarcusTextStyle *emphasis;
|
|
124
|
+
@property(nonatomic, strong) RCTMarcusTextStyle *strikethrough;
|
|
125
|
+
@property(nonatomic, strong) RCTMarcusHeadingStyle *heading;
|
|
126
|
+
@property(nonatomic, strong) RCTMarcusEmojiStyle *emoji;
|
|
127
|
+
@property(nonatomic, strong) RCTMarcusBlockquoteStyle *blockquote;
|
|
128
|
+
@property(nonatomic, strong) RCTMarcusListStyle *orderedList;
|
|
129
|
+
@property(nonatomic, strong) RCTMarcusListStyle *unorderedList;
|
|
130
|
+
@property(nonatomic, strong) RCTMarcusBoxStyle *code;
|
|
131
|
+
@property(nonatomic, strong) RCTMarcusBoxStyle *pre;
|
|
132
|
+
/// A name with an `@` in front of it, drawn as a pill: the same inline box an
|
|
133
|
+
/// inline run of code sits in, and so the same lengths.
|
|
134
|
+
@property(nonatomic, strong) RCTMarcusBoxStyle *mention;
|
|
38
135
|
|
|
39
136
|
@end
|
|
40
137
|
|
package/apple/RCTMarcusStyle.m
CHANGED
|
@@ -1,5 +1,53 @@
|
|
|
1
1
|
#import <RNMarcus/RCTMarcusStyle.h>
|
|
2
2
|
|
|
3
|
+
@implementation RCTMarcusTextStyle
|
|
4
|
+
@end
|
|
5
|
+
|
|
6
|
+
@implementation RCTMarcusBoxStyle
|
|
7
|
+
@end
|
|
8
|
+
|
|
9
|
+
@implementation RCTMarcusHeadingStyle
|
|
10
|
+
@end
|
|
11
|
+
|
|
12
|
+
@implementation RCTMarcusBlockquoteStyle
|
|
13
|
+
@end
|
|
14
|
+
|
|
15
|
+
@implementation RCTMarcusListStyle
|
|
16
|
+
|
|
17
|
+
- (instancetype)init {
|
|
18
|
+
if (self = [super init]) {
|
|
19
|
+
_marker = [RCTMarcusTextStyle new];
|
|
20
|
+
}
|
|
21
|
+
return self;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@end
|
|
25
|
+
|
|
26
|
+
@implementation RCTMarcusEmojiStyle
|
|
27
|
+
@end
|
|
28
|
+
|
|
3
29
|
@implementation RCTMarcusStyle
|
|
4
30
|
|
|
31
|
+
// Every entry exists whether or not the style named it, so that a formatter can
|
|
32
|
+
// read one without asking first: an entry that says nothing is an entry whose
|
|
33
|
+
// every property is unset, which is exactly what "inherit" means here.
|
|
34
|
+
- (instancetype)init {
|
|
35
|
+
if (self = [super init]) {
|
|
36
|
+
_syntax = [RCTMarcusTextStyle new];
|
|
37
|
+
_link = [RCTMarcusTextStyle new];
|
|
38
|
+
_strong = [RCTMarcusTextStyle new];
|
|
39
|
+
_emphasis = [RCTMarcusTextStyle new];
|
|
40
|
+
_strikethrough = [RCTMarcusTextStyle new];
|
|
41
|
+
_heading = [RCTMarcusHeadingStyle new];
|
|
42
|
+
_emoji = [RCTMarcusEmojiStyle new];
|
|
43
|
+
_blockquote = [RCTMarcusBlockquoteStyle new];
|
|
44
|
+
_orderedList = [RCTMarcusListStyle new];
|
|
45
|
+
_unorderedList = [RCTMarcusListStyle new];
|
|
46
|
+
_code = [RCTMarcusBoxStyle new];
|
|
47
|
+
_pre = [RCTMarcusBoxStyle new];
|
|
48
|
+
_mention = [RCTMarcusBoxStyle new];
|
|
49
|
+
}
|
|
50
|
+
return self;
|
|
51
|
+
}
|
|
52
|
+
|
|
5
53
|
@end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#import <React/RCTParagraphComponentView.h>
|
|
2
|
+
|
|
3
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
4
|
+
|
|
5
|
+
// Copying a paragraph that has drawings in it.
|
|
6
|
+
//
|
|
7
|
+
// A view nested in a `Text` is one U+FFFC in the attributed string React Native
|
|
8
|
+
// lays out, and U+FFFC is what its own `copy:` puts on the pasteboard: an
|
|
9
|
+
// equation arrives in the next application as an empty box. This replaces the
|
|
10
|
+
// copy with one that writes each of those characters back out as the markdown
|
|
11
|
+
// it stands for -- but only for a paragraph inside a `MarcusTextDecoratorView`
|
|
12
|
+
// that reported any, so every other `Text` in the application copies exactly as
|
|
13
|
+
// it did before.
|
|
14
|
+
@interface RCTParagraphComponentView (Marcus)
|
|
15
|
+
@end
|
|
16
|
+
|
|
17
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#import <RNMarcus/MarcusSwizzle.h>
|
|
2
|
+
#import <RNMarcus/MarcusTextDecoratorComponentView.h>
|
|
3
|
+
#import <RNMarcus/RCTParagraphComponentView+Marcus.h>
|
|
4
|
+
|
|
5
|
+
@implementation RCTParagraphComponentView (Marcus)
|
|
6
|
+
|
|
7
|
+
- (void)marcus_copy:(id)sender {
|
|
8
|
+
// The decorator is this view's superview: it has a host view of its own
|
|
9
|
+
// precisely so that it can sit there, and it is the only thing that knows
|
|
10
|
+
// what the placeholders in this paragraph stand for.
|
|
11
|
+
UIView *parent = self.superview;
|
|
12
|
+
|
|
13
|
+
NSString *source =
|
|
14
|
+
[parent isKindOfClass:[MarcusTextDecoratorComponentView class]]
|
|
15
|
+
? [(MarcusTextDecoratorComponentView *)parent substitutedTextOf:self.attributedText]
|
|
16
|
+
: nil;
|
|
17
|
+
|
|
18
|
+
if (source == nil) {
|
|
19
|
+
[self marcus_copy:sender];
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Plain text alone, where React Native would also put RTF. What is on the
|
|
24
|
+
// pasteboard now is markdown -- the source of the paragraph, dollar signs and
|
|
25
|
+
// all -- and there is no rich-text rendering of that worth carrying: the
|
|
26
|
+
// markup that says how it looked is the very thing being copied out.
|
|
27
|
+
UIPasteboard.generalPasteboard.string = source;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
+ (void)load {
|
|
31
|
+
static dispatch_once_t onceToken;
|
|
32
|
+
dispatch_once(&onceToken, ^{
|
|
33
|
+
// Implemented by this class, so this is a plain exchange.
|
|
34
|
+
RCTMarcusSwizzle([self class], @selector(copy:), @selector(marcus_copy:));
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#import <RNMarcus/MarkdownAttributes.h>
|
|
2
2
|
#import <RNMarcus/MarcusTextInputDecoratorComponentView.h>
|
|
3
|
+
#import <RNMarcus/MarcusSwizzle.h>
|
|
3
4
|
#import <RNMarcus/RCTTextInputComponentView+Marcus.h>
|
|
4
|
-
#import <objc/message.h>
|
|
5
5
|
|
|
6
6
|
@implementation RCTTextInputComponentView (Marcus)
|
|
7
7
|
|
|
@@ -39,30 +39,6 @@
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
// Installs `swizzledSelector` in place of `originalSelector` on `cls`.
|
|
43
|
-
//
|
|
44
|
-
// method_exchangeImplementations alone is only safe when `cls` implements
|
|
45
|
-
// `originalSelector` itself. For an inherited method -- didAddSubview:, for
|
|
46
|
-
// instance -- class_getInstanceMethod returns the *superclass's* method, and
|
|
47
|
-
// exchanging it rewrites UIView for every view in the app. So the
|
|
48
|
-
// implementation is added to this class first; when that succeeds, the
|
|
49
|
-
// "call the original" selector is pointed at the inherited implementation.
|
|
50
|
-
static void
|
|
51
|
-
RCTMarcusSwizzle(Class cls, SEL originalSelector, SEL swizzledSelector) {
|
|
52
|
-
Method originalMethod = class_getInstanceMethod(cls, originalSelector);
|
|
53
|
-
Method swizzledMethod = class_getInstanceMethod(cls, swizzledSelector);
|
|
54
|
-
if (originalMethod == NULL || swizzledMethod == NULL) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
BOOL didAddMethod = class_addMethod(cls, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
|
|
59
|
-
if (didAddMethod) {
|
|
60
|
-
class_replaceMethod(cls, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
|
|
61
|
-
} else {
|
|
62
|
-
method_exchangeImplementations(originalMethod, swizzledMethod);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
42
|
+ (void)load {
|
|
67
43
|
static dispatch_once_t onceToken;
|
|
68
44
|
dispatch_once(&onceToken, ^{
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <react/renderer/core/ShadowNodeFamily.h>
|
|
5
|
+
|
|
6
|
+
namespace facebook {
|
|
7
|
+
namespace react {
|
|
8
|
+
|
|
9
|
+
// The decorator carries no state of its own; the formatting it applies lives on
|
|
10
|
+
// the text layout manager it hands to the child. This exists only because a
|
|
11
|
+
// shadow node has to name a state type, and because Android's mounting layer
|
|
12
|
+
// wants one it can serialize.
|
|
13
|
+
class JSI_EXPORT MarcusTextDecoratorState final {
|
|
14
|
+
public:
|
|
15
|
+
using Shared = std::shared_ptr<const MarcusTextDecoratorState>;
|
|
16
|
+
|
|
17
|
+
MarcusTextDecoratorState() {};
|
|
18
|
+
|
|
19
|
+
// TODO: Simplify once RN 0.81 is the lowest supported version
|
|
20
|
+
#if (defined(ANDROID) && REACT_NATIVE_MINOR_VERSION < 81) || (defined(RN_SERIALIZABLE_STATE) && REACT_NATIVE_MINOR_VERSION >= 81)
|
|
21
|
+
MarcusTextDecoratorState(
|
|
22
|
+
MarcusTextDecoratorState const &previousState, folly::dynamic data
|
|
23
|
+
) {};
|
|
24
|
+
|
|
25
|
+
folly::dynamic
|
|
26
|
+
getDynamic() const {
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
#if REACT_NATIVE_MINOR_VERSION < 81
|
|
30
|
+
MapBuffer
|
|
31
|
+
getMapBuffer() const { return MapBufferBuilder::EMPTY(); };
|
|
32
|
+
#endif // REACT_NATIVE_MINOR_VERSION < 81
|
|
33
|
+
#endif // (defined(ANDROID) && REACT_NATIVE_MINOR_VERSION < 81) || (defined(RN_SERIALIZABLE_STATE) && REACT_NATIVE_MINOR_VERSION >= 81)
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
} // namespace react
|
|
37
|
+
} // namespace facebook
|
package/cpp/react/renderer/components/RNMarcusSpec/MarcusTextDecoratorViewComponentDescriptor.h
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "MarcusTextDecoratorShadowNode.h"
|
|
4
|
+
#include <react/debug/react_native_assert.h>
|
|
5
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
6
|
+
|
|
7
|
+
namespace facebook {
|
|
8
|
+
namespace react {
|
|
9
|
+
|
|
10
|
+
class MarcusTextDecoratorViewComponentDescriptor final
|
|
11
|
+
: public ConcreteComponentDescriptor<MarcusTextDecoratorShadowNode> {
|
|
12
|
+
public:
|
|
13
|
+
using ConcreteComponentDescriptor::ConcreteComponentDescriptor;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
} // namespace react
|
|
17
|
+
} // namespace facebook
|