Skip to content

Commit 7f502d2

Browse files
committed
rename
1 parent 9c85785 commit 7f502d2

7 files changed

Lines changed: 35 additions & 36 deletions

File tree

android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdown.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import com.swmansion.enriched.markdown.utils.common.FeatureFlags
1818
import com.swmansion.enriched.markdown.utils.common.MarkdownSegmentRenderer
1919
import com.swmansion.enriched.markdown.utils.common.RenderedSegment
2020
import com.swmansion.enriched.markdown.utils.common.splitASTIntoSegments
21-
import com.swmansion.enriched.markdown.utils.text.view.applyMarkdownSelectionColors
21+
import com.swmansion.enriched.markdown.utils.text.view.applySelectionColors
2222
import com.swmansion.enriched.markdown.utils.text.view.emitLinkLongPressEvent
2323
import com.swmansion.enriched.markdown.utils.text.view.emitLinkPressEvent
2424
import com.swmansion.enriched.markdown.views.BlockSegmentView
@@ -55,8 +55,8 @@ class EnrichedMarkdown
5555
private var maxFontSizeMultiplier: Float = 0f
5656
private var allowTrailingMargin: Boolean = false
5757
private var selectable: Boolean = true
58-
private var propSelectionColor: Int? = null
59-
private var propSelectionHandleColor: Int? = null
58+
private var selectionColor: Int? = null
59+
private var selectionHandleColor: Int? = null
6060

6161
private var onLinkPressCallback: ((String) -> Unit)? = null
6262
private var onLinkLongPressCallback: ((String) -> Unit)? = null
@@ -131,19 +131,19 @@ class EnrichedMarkdown
131131
}
132132
}
133133

134-
fun setSelectionColorFromProps(color: Int?) {
135-
propSelectionColor = color
134+
fun setSelectionColor(color: Int?) {
135+
selectionColor = color
136136
applySelectionColorsToSegments()
137137
}
138138

139-
fun setSelectionHandleColorFromProps(color: Int?) {
140-
propSelectionHandleColor = color
139+
fun setSelectionHandleColor(color: Int?) {
140+
selectionHandleColor = color
141141
applySelectionColorsToSegments()
142142
}
143143

144144
private fun applySelectionColorsToSegments() {
145145
segmentViews.filterIsInstance<EnrichedMarkdownInternalText>().forEach {
146-
it.applyMarkdownSelectionColors(propSelectionColor, propSelectionHandleColor)
146+
it.applySelectionColors(selectionColor, selectionHandleColor)
147147
}
148148
}
149149

@@ -254,7 +254,7 @@ class EnrichedMarkdown
254254
setContextMenuItems(contextMenuItemTexts, ::forwardContextMenuItemPress)
255255
}
256256

257-
applyMarkdownSelectionColors(propSelectionColor, propSelectionHandleColor)
257+
applySelectionColors(selectionColor, selectionHandleColor)
258258
}
259259

260260
private fun createTableView(

android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownManager.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ class EnrichedMarkdownManager :
8484
view: EnrichedMarkdown?,
8585
value: Int?,
8686
) {
87-
view?.setSelectionColorFromProps(value)
87+
view?.setSelectionColor(value)
8888
}
8989

9090
override fun setSelectionHandleColor(
9191
view: EnrichedMarkdown?,
9292
value: Int?,
9393
) {
94-
view?.setSelectionHandleColorFromProps(value)
94+
view?.setSelectionHandleColor(value)
9595
}
9696

9797
@ReactProp(name = "md4cFlags")

android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownText.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import com.swmansion.enriched.markdown.styles.StyleConfig
2222
import com.swmansion.enriched.markdown.utils.text.TailFadeInAnimator
2323
import com.swmansion.enriched.markdown.utils.text.interaction.CheckboxTouchHelper
2424
import com.swmansion.enriched.markdown.utils.text.view.LinkLongPressMovementMethod
25-
import com.swmansion.enriched.markdown.utils.text.view.applyMarkdownSelectionColors
2625
import com.swmansion.enriched.markdown.utils.text.view.applySelectableState
26+
import com.swmansion.enriched.markdown.utils.text.view.applySelectionColors
2727
import com.swmansion.enriched.markdown.utils.text.view.cancelJSTouchForCheckboxTap
2828
import com.swmansion.enriched.markdown.utils.text.view.cancelJSTouchForLinkTap
2929
import com.swmansion.enriched.markdown.utils.text.view.createSelectionActionModeCallback
@@ -82,8 +82,8 @@ class EnrichedMarkdownText
8282
private set
8383
var spoilerOverlay: SpoilerOverlay = SpoilerOverlay.PARTICLES
8484

85-
private var propSelectionColor: Int? = null
86-
private var propSelectionHandleColor: Int? = null
85+
private var selectionColor: Int? = null
86+
private var selectionHandleColor: Int? = null
8787

8888
init {
8989
setupAsMarkdownTextView()
@@ -253,7 +253,7 @@ class EnrichedMarkdownText
253253
previousTextLength = styledText.length
254254
}
255255

256-
applyMarkdownSelectionColors(propSelectionColor, propSelectionHandleColor)
256+
applySelectionColors(selectionColor, selectionHandleColor)
257257
}
258258

259259
fun setContextMenuItems(items: List<String>) {
@@ -264,14 +264,14 @@ class EnrichedMarkdownText
264264
applySelectableState(selectable)
265265
}
266266

267-
fun setSelectionColorFromProps(color: Int?) {
268-
propSelectionColor = color
269-
applyMarkdownSelectionColors(propSelectionColor, propSelectionHandleColor)
267+
fun setSelectionColor(color: Int?) {
268+
selectionColor = color
269+
applySelectionColors(selectionColor, selectionHandleColor)
270270
}
271271

272-
fun setSelectionHandleColorFromProps(color: Int?) {
273-
propSelectionHandleColor = color
274-
applyMarkdownSelectionColors(propSelectionColor, propSelectionHandleColor)
272+
fun setSelectionHandleColor(color: Int?) {
273+
selectionHandleColor = color
274+
applySelectionColors(selectionColor, selectionHandleColor)
275275
}
276276

277277
fun emitOnLinkPress(url: String) {

android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownTextManager.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ class EnrichedMarkdownTextManager :
104104
view: EnrichedMarkdownText?,
105105
value: Int?,
106106
) {
107-
view?.setSelectionColorFromProps(value)
107+
view?.setSelectionColor(value)
108108
}
109109

110110
override fun setSelectionHandleColor(
111111
view: EnrichedMarkdownText?,
112112
value: Int?,
113113
) {
114-
view?.setSelectionHandleColorFromProps(value)
114+
view?.setSelectionHandleColor(value)
115115
}
116116

117117
@ReactProp(name = "md4cFlags")

android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/TextSelectionColors.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import androidx.core.graphics.drawable.DrawableCompat
1111
* Handle drawables are only tinted on API 29+ where the framework exposes getters;
1212
* on older versions the handle theme defaults remain unchanged.
1313
*/
14-
fun TextView.applyMarkdownSelectionColors(
14+
fun TextView.applySelectionColors(
1515
selectionColor: Int?,
1616
selectionHandleColor: Int?,
1717
) {

ios/EnrichedMarkdown.mm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ + (instancetype)segmentWithLatex:(NSString *)latex
9191
#endif
9292

9393
@interface EnrichedMarkdown () <RCTEnrichedMarkdownViewProtocol, UITextViewDelegate>
94-
- (void)applySelectionTintFromProps:(const EnrichedMarkdownProps &)props toTextView:(ENRMPlatformTextView *)textView;
94+
- (void)applySelectionColor:(const EnrichedMarkdownProps &)props toTextView:(ENRMPlatformTextView *)textView;
9595
@end
9696

9797
@implementation EnrichedMarkdown {
@@ -496,7 +496,7 @@ - (EnrichedMarkdownInternalText *)createTextViewForRenderedSegment:(ENRMRenderRe
496496
[view applyAttributedText:segment.attributedText context:segment.context];
497497

498498
const auto &selectionProps = *std::static_pointer_cast<EnrichedMarkdownProps const>(self->_props);
499-
[self applySelectionTintFromProps:selectionProps toTextView:view.textView];
499+
[self applySelectionColor:selectionProps toTextView:view.textView];
500500

501501
ENRMTapRecognizer *tapRecognizer = [[ENRMTapRecognizer alloc] initWithTarget:self action:@selector(textTapped:)];
502502
[view.textView addGestureRecognizer:tapRecognizer];
@@ -667,7 +667,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
667667
for (RCTUIView *segment in _segmentViews) {
668668
if ([segment isKindOfClass:[EnrichedMarkdownInternalText class]]) {
669669
ENRMPlatformTextView *tv = ((EnrichedMarkdownInternalText *)segment).textView;
670-
[self applySelectionTintFromProps:newViewProps toTextView:tv];
670+
[self applySelectionColor:newViewProps toTextView:tv];
671671
}
672672
}
673673
#endif
@@ -896,7 +896,7 @@ - (NSInteger)indexOfAccessibilityElement:(id)element
896896
}
897897
#endif
898898

899-
- (void)applySelectionTintFromProps:(const EnrichedMarkdownProps &)props toTextView:(ENRMPlatformTextView *)textView
899+
- (void)applySelectionColor:(const EnrichedMarkdownProps &)props toTextView:(ENRMPlatformTextView *)textView
900900
{
901901
#if !TARGET_OS_OSX
902902
if (isColorMeaningful(props.selectionColor)) {

src/web/EnrichedMarkdownText.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type { ASTNode, RendererCallbacks, RenderCapabilities } from './types';
1818
import { indexTaskItems, markInlineImages } from './utils';
1919
import { loadKaTeX } from './katex';
2020
import type { KaTeXInstance } from './katex';
21+
import { normalizeColor } from '../styleUtils';
2122

2223
export const EnrichedMarkdownText = ({
2324
markdown,
@@ -103,10 +104,9 @@ export const EnrichedMarkdownText = ({
103104
);
104105

105106
const wrapperStyle = useMemo<CSSProperties>(() => {
106-
const selectionBgVar =
107-
selectionColor != null && selectionColor !== undefined
108-
? String(selectionColor)
109-
: undefined;
107+
const selectionBgVar = selectionColor
108+
? normalizeColor(String(selectionColor))
109+
: undefined;
110110

111111
return {
112112
display: 'flex',
@@ -119,12 +119,11 @@ export const EnrichedMarkdownText = ({
119119
};
120120
}, [containerStyle, selectable, selectionColor]);
121121

122-
const selectionStyle =
123-
selectionColor != null && selectionColor !== undefined ? (
124-
<style>{`[data-enriched-markdown-text] ::selection {
122+
const selectionStyle = selectionColor ? (
123+
<style>{`[data-enriched-markdown-text] ::selection {
125124
background-color: var(--enrm-selection-bg);
126125
}`}</style>
127-
) : null;
126+
) : null;
128127

129128
if (parseError) {
130129
return (

0 commit comments

Comments
 (0)