diff --git a/apps/macos-example/src/App.tsx b/apps/macos-example/src/App.tsx index c879f8b0..6f681aff 100644 --- a/apps/macos-example/src/App.tsx +++ b/apps/macos-example/src/App.tsx @@ -83,6 +83,7 @@ export default function App() { onLinkPress={handleLinkPress} markdownStyle={markdownStyle} contextMenuItems={contextMenuItems} + selectionColor="#DCDDFE" /> {lastLink != null && ( diff --git a/ios/utils/ENRMUIKit.h b/ios/utils/ENRMUIKit.h index 477e5fed..4508a139 100644 --- a/ios/utils/ENRMUIKit.h +++ b/ios/utils/ENRMUIKit.h @@ -203,12 +203,16 @@ static inline void ENRMSetCursorColor(ENRMPlatformTextView *textView, RCTUIColor #endif } -/// Cross-platform selection color: iOS uses tintColor (affects both cursor and selection); -/// macOS selection highlight is managed by the system and not directly settable. +/// Cross-platform selection color: iOS uses tintColor (also affects the caret +/// and selection handles); macOS sets the selection background via +/// `selectedTextAttributes`. Pass `nil` to restore the system default. static inline void ENRMSetSelectionColor(ENRMPlatformTextView *textView, RCTUIColor *color) { #if !TARGET_OS_OSX textView.tintColor = color; +#else + RCTUIColor *resolved = color ?: [NSColor selectedTextBackgroundColor]; + textView.selectedTextAttributes = @{NSBackgroundColorAttributeName : resolved}; #endif } diff --git a/src/EnrichedMarkdownNativeComponent.ts b/src/EnrichedMarkdownNativeComponent.ts index 71b3d8ac..80747ff7 100644 --- a/src/EnrichedMarkdownNativeComponent.ts +++ b/src/EnrichedMarkdownNativeComponent.ts @@ -277,9 +277,10 @@ export interface NativeProps extends ViewProps { * Color of the text selection highlight. * * On iOS, this also affects the caret and selection handle colors - * (they share a single tint). + * (they share a single tint). On macOS, only the selection background + * is affected. * - * @platform ios, android, web + * @platform ios, android, macos, web */ selectionColor?: ColorValue; /** diff --git a/src/EnrichedMarkdownTextNativeComponent.ts b/src/EnrichedMarkdownTextNativeComponent.ts index 13add176..71011506 100644 --- a/src/EnrichedMarkdownTextNativeComponent.ts +++ b/src/EnrichedMarkdownTextNativeComponent.ts @@ -277,9 +277,10 @@ export interface NativeProps extends ViewProps { * Color of the text selection highlight. * * On iOS, this also affects the caret and selection handle colors - * (they share a single tint). + * (they share a single tint). On macOS, only the selection background + * is affected. * - * @platform ios, android, web + * @platform ios, android, macos, web */ selectionColor?: ColorValue; /** diff --git a/src/types/MarkdownTextProps.ts b/src/types/MarkdownTextProps.ts index bade9723..b38dee8d 100644 --- a/src/types/MarkdownTextProps.ts +++ b/src/types/MarkdownTextProps.ts @@ -95,9 +95,10 @@ export interface EnrichedMarkdownTextProps extends Omit { * Color of the text selection highlight. * * On iOS, this also affects the caret and selection handle colors - * (they share a single tint). + * (they share a single tint). On macOS, only the selection background + * is affected. * - * @platform ios, android, web + * @platform ios, android, macos, web */ selectionColor?: ColorValue; /**