Skip to content

Commit 9690c04

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix/web-folder-mentions-open-in-tree
2 parents 2d7d389 + 6d1d549 commit 9690c04

322 files changed

Lines changed: 20684 additions & 8404 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/desktop/scripts/verify-preload-bundle.mjs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { parse } from "acorn";
99
const expectedDesktopBridgeApis = [
1010
"getClientPlatform",
1111
"getLocalEnvironmentBootstraps",
12+
"getPathForFile",
1213
"pickFolder",
1314
];
1415
const clerkPasskeysGlobal = "__clerk_internal_electron_passkeys";
@@ -68,6 +69,9 @@ const createSandboxModules = (exposedGlobals) => {
6869
exposeInMainWorld: (name, api) => exposedGlobals.set(name, api),
6970
},
7071
ipcRenderer,
72+
webUtils: {
73+
getPathForFile: () => "",
74+
},
7175
};
7276

7377
return new Map([

‎apps/desktop/scripts/verify-preload-bundle.test.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const validPreload = `
99
electron.contextBridge.exposeInMainWorld("desktopBridge", {
1010
getClientPlatform: () => process.platform,
1111
getLocalEnvironmentBootstraps: () => [],
12+
getPathForFile: () => "",
1213
pickFolder: (options) => electron.ipcRenderer.invoke(PICK_FOLDER_CHANNEL, options),
1314
});
1415
`;

‎apps/desktop/src/preload.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
DesktopSnapShotEvent,
77
} from "@t3tools/contracts";
88
import { exposeClerkBridge } from "@clerk/electron/preload";
9-
import { contextBridge, ipcRenderer, webFrame } from "electron";
9+
import { contextBridge, ipcRenderer, webFrame, webUtils } from "electron";
1010

1111
import * as IpcChannels from "./ipc/channels.ts";
1212

@@ -69,6 +69,7 @@ contextBridge.exposeInMainWorld("desktopBridge", {
6969
}
7070
return result as ReturnType<DesktopBridge["getAppBranding"]>;
7171
},
72+
getPathForFile: (file: File) => webUtils.getPathForFile(file),
7273
getClientPlatform: () => clientPlatform,
7374
setNotificationBadge: (badge) =>
7475
ipcRenderer.invoke(IpcChannels.SET_NOTIFICATION_BADGE_CHANNEL, badge),

‎apps/mobile/app.config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ const config: ExpoConfig = {
214214
slug: "t3-code",
215215
platforms: ["ios", "android"],
216216
scheme: variant.scheme,
217-
version: "1.2.0",
217+
version: "1.2.1",
218218
runtimeVersion: {
219219
// Development manifests resolve on every launch, so avoid fingerprint's
220220
// expensive native-project calculation there. Preview and production stay
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!-- Tabler Icons edit (MIT), matching AppSymbol's square.and.pencil.
2+
Strokes expanded to fills: Expo UI's vector parser does not support strokes. -->
3+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:width="24dp" android:height="24dp"
5+
android:viewportWidth="24" android:viewportHeight="24">
6+
<path android:fillColor="#000000"
7+
android:pathData="M7,6 L6,6 C4.3431,6 3,7.3431 3,9 L3,18 C3,19.6569 4.3431,21 6,21 L15,21 C16.6569,21 18,19.6569 18,18 L18,17 C18,16.4477 17.5523,16 17,16 C16.4477,16 16,16.4477 16,17 L16,18 C16,18.5523 15.5523,19 15,19 L6,19 C5.4477,19 5,18.5523 5,18 L5,9 C5,8.4477 5.4477,8 6,8 L7,8 C7.5523,8 8,7.5523 8,7 C8,6.4477 7.5523,6 7,6 Z M21.0921,5.8779 L21.092,5.8778 L20.3849,6.5849 L21.092,7.292 C22.3027,6.0814 22.3027,4.1186 21.092,2.908 C19.8814,1.6973 17.9186,1.6973 16.708,2.908 L8.2942,11.2916 C8.1059,11.4793 8,11.7342 8,12 L8,15 C8,15.5523 8.4477,16 9,16 L12,16 C12.2658,16 12.5207,15.8942 12.7084,15.7058 L21.0934,7.2908 C21.4832,6.8996 21.4821,6.2665 21.0908,5.8766 C20.6996,5.4868 20.0665,5.4879 19.6766,5.8792 L11.2916,14.2942 L12,14 L9,14 L10,15 L10,12 L9.7058,12.7084 L18.1209,4.3235 C18.5518,3.8926 19.2482,3.8926 19.6778,4.3222 C20.1074,4.7518 20.1074,5.4482 19.6778,5.8778 C19.2873,6.2683 19.2873,6.9015 19.6778,7.292 L19.6779,7.2921 C20.0684,7.6826 20.7016,7.6826 21.0921,7.2921 C21.4826,6.9016 21.4826,6.2684 21.0921,5.8779 Z M15.2929,5.7071 L18.2929,8.7071 C18.6834,9.0976 19.3166,9.0976 19.7071,8.7071 C20.0976,8.3166 20.0976,7.6834 19.7071,7.2929 L16.7071,4.2929 C16.3166,3.9024 15.6834,3.9024 15.2929,4.2929 C14.9024,4.6834 14.9024,5.3166 15.2929,5.7071 Z" />
8+
</vector>

‎apps/mobile/modules/t3-markdown-text/android/src/main/java/expo/modules/t3markdowntext/T3MarkdownTextSelectionModule.kt‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.graphics.Canvas
88
import android.graphics.Color
99
import android.graphics.Paint
1010
import android.graphics.Typeface
11+
import android.os.Build
1112
import android.text.Spannable
1213
import android.text.SpannableStringBuilder
1314
import android.text.Spanned
@@ -164,6 +165,17 @@ private class SanitizingSelectionActionModeCallback(
164165
}
165166
}
166167

168+
internal fun applySelectionHandleColor(textView: TextView, color: Int) {
169+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) return
170+
textView.textSelectHandle?.mutate()?.apply { setTint(color) }?.let(textView::setTextSelectHandle)
171+
textView.textSelectHandleLeft?.mutate()?.apply {
172+
setTint(color)
173+
}?.let(textView::setTextSelectHandleLeft)
174+
textView.textSelectHandleRight?.mutate()?.apply {
175+
setTint(color)
176+
}?.let(textView::setTextSelectHandleRight)
177+
}
178+
167179
class T3MarkdownTextSelectionModule : Module() {
168180
private val chipImages = LruCache<String, Map<String, Any>>(128)
169181

@@ -183,9 +195,23 @@ class T3MarkdownTextSelectionModule : Module() {
183195
}
184196
}.fontMetricsInt
185197

198+
private fun setSelectionHandleColor(reactTag: Int, color: Int) {
199+
val reactContext = appContext.reactContext as? ReactContext ?: return
200+
reactContext.runOnUiQueueThread {
201+
val textView = runCatching {
202+
UIManagerHelper.getUIManagerForReactTag(reactContext, reactTag)?.resolveView(reactTag)
203+
}.getOrNull() as? TextView ?: return@runOnUiQueueThread
204+
applySelectionHandleColor(textView, color)
205+
}
206+
}
207+
186208
override fun definition() = ModuleDefinition {
187209
Name("T3MarkdownTextSelection")
188210

211+
Function("setSelectionHandleColor") { reactTag: Int, color: Int ->
212+
setSelectionHandleColor(reactTag, color)
213+
}
214+
189215
Function("renderContextChip") { payloadJson: String ->
190216
val resources = appContext.reactContext?.resources ?: return@Function null
191217
val metrics = resources.displayMetrics
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package expo.modules.t3markdowntext
2+
3+
import android.graphics.Bitmap
4+
import android.graphics.Canvas
5+
import android.graphics.Color
6+
import android.graphics.drawable.ColorDrawable
7+
import android.graphics.drawable.Drawable
8+
import android.widget.TextView
9+
import org.junit.Assert.assertEquals
10+
import org.junit.Test
11+
import org.junit.runner.RunWith
12+
import org.robolectric.RobolectricTestRunner
13+
import org.robolectric.RuntimeEnvironment
14+
import org.robolectric.annotation.Config
15+
import org.robolectric.annotation.GraphicsMode
16+
17+
@RunWith(RobolectricTestRunner::class)
18+
@Config(sdk = [36], manifest = Config.NONE)
19+
@GraphicsMode(GraphicsMode.Mode.NATIVE)
20+
class MarkdownSelectionColorTest {
21+
private fun textView() = TextView(RuntimeEnvironment.getApplication()).apply {
22+
setTextSelectHandle(ColorDrawable(Color.WHITE))
23+
setTextSelectHandleLeft(ColorDrawable(Color.WHITE))
24+
setTextSelectHandleRight(ColorDrawable(Color.WHITE))
25+
}
26+
27+
private fun renderedColor(drawable: Drawable?): Int {
28+
requireNotNull(drawable)
29+
val bitmap = Bitmap.createBitmap(4, 4, Bitmap.Config.ARGB_8888)
30+
drawable.setBounds(0, 0, 4, 4)
31+
drawable.draw(Canvas(bitmap))
32+
val color = bitmap.getPixel(2, 2)
33+
bitmap.recycle()
34+
return color
35+
}
36+
37+
@Test
38+
fun retintsAllHandlesWhenTheThemeChangesWithoutChangingTheHighlight() {
39+
val text = textView()
40+
val highlight = 0x52FF0088
41+
text.highlightColor = highlight
42+
43+
for (color in listOf(Color.MAGENTA, Color.GREEN, Color.MAGENTA)) {
44+
applySelectionHandleColor(text, color)
45+
assertEquals(color, renderedColor(text.textSelectHandle))
46+
assertEquals(color, renderedColor(text.textSelectHandleLeft))
47+
assertEquals(color, renderedColor(text.textSelectHandleRight))
48+
assertEquals(highlight, text.highlightColor)
49+
}
50+
}
51+
52+
@Test
53+
fun doesNotTintOtherTextViewsSharingDrawableState() {
54+
val original = ColorDrawable(Color.WHITE)
55+
val first = textView().apply {
56+
setTextSelectHandleLeft(original.constantState!!.newDrawable())
57+
}
58+
val second = textView().apply {
59+
setTextSelectHandleLeft(original.constantState!!.newDrawable())
60+
}
61+
62+
applySelectionHandleColor(first, Color.MAGENTA)
63+
64+
assertEquals(Color.MAGENTA, renderedColor(first.textSelectHandleLeft))
65+
assertEquals(Color.WHITE, renderedColor(second.textSelectHandleLeft))
66+
}
67+
}

‎apps/mobile/modules/t3-markdown-text/src/MarkdownTextPrimitive.tsx‎

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import React, { type Ref } from "react";
2-
import { Platform, StyleSheet, Text as RNText, type TextProps, type ViewStyle } from "react-native";
2+
import {
3+
findNodeHandle,
4+
Platform,
5+
processColor,
6+
StyleSheet,
7+
Text as RNText,
8+
type ColorValue,
9+
type TextProps,
10+
type ViewStyle,
11+
} from "react-native";
12+
import { setMarkdownSelectionHandleColor } from "./T3MarkdownTextSelectionModule";
313
import T3MarkdownTextRunNativeComponent from "./T3MarkdownTextRunNativeComponent";
414
import T3MarkdownTextNativeComponent from "./T3MarkdownTextNativeComponent";
515
import { flattenStyles } from "./util";
@@ -34,6 +44,7 @@ export type ContextMenuActionEvent = {
3444
*/
3545
export type MarkdownTextPrimitiveProps = Omit<TextProps, "onTextLayout"> & {
3646
nativeTextRef?: Ref<RNText>;
47+
selectionHandleColor?: ColorValue;
3748
uiTextView?: boolean;
3849
contextMenuConfig?: string;
3950
contextClipboardConfig?: string;
@@ -116,7 +127,45 @@ function MarkdownTextPrimitiveInner({ nativeTextRef, ...props }: MarkdownTextPri
116127
return <MarkdownTextPrimitiveChild {...props} />;
117128
}
118129

119-
export function MarkdownTextPrimitive(props: MarkdownTextPrimitiveProps) {
130+
function AndroidMarkdownText({
131+
nativeTextRef,
132+
selectionHandleColor,
133+
onLayout,
134+
contextClipboardConfig: _contextClipboardConfig,
135+
...props
136+
}: MarkdownTextPrimitiveProps) {
137+
const textRef = React.useRef<RNText | null>(null);
138+
React.useImperativeHandle<RNText | null, RNText | null>(nativeTextRef, () => textRef.current, []);
139+
const color = processColor(selectionHandleColor);
140+
const applyHandleColor = React.useCallback(() => {
141+
if (!textRef.current || typeof color !== "number") return;
142+
const reactTag = findNodeHandle(textRef.current);
143+
if (reactTag !== null) setMarkdownSelectionHandleColor(reactTag, color);
144+
}, [color]);
145+
146+
// RN's selectionColor only sets the highlight. Retint mounted handles when
147+
// the theme changes, and after layout when the native view first exists.
148+
React.useEffect(applyHandleColor, [applyHandleColor]);
149+
150+
return (
151+
<RNText
152+
ref={textRef}
153+
{...props}
154+
onLayout={(event) => {
155+
applyHandleColor();
156+
onLayout?.(event);
157+
}}
158+
/>
159+
);
160+
}
161+
162+
export function MarkdownTextPrimitive({
163+
selectionHandleColor,
164+
...props
165+
}: MarkdownTextPrimitiveProps) {
166+
if (Platform.OS === "android" && selectionHandleColor !== undefined) {
167+
return <AndroidMarkdownText {...props} selectionHandleColor={selectionHandleColor} />;
168+
}
120169
if (Platform.OS !== "ios") {
121170
const { nativeTextRef, contextClipboardConfig: _contextClipboardConfig, ...textProps } = props;
122171
return <RNText ref={nativeTextRef} {...textProps} />;

‎apps/mobile/modules/t3-markdown-text/src/NativeMarkdownBlock.tsx‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,13 @@ function HighlightedCodeText(props: {
133133
}
134134
}
135135
return (
136-
<MarkdownTextPrimitive uiTextView selectable style={style}>
136+
<MarkdownTextPrimitive
137+
uiTextView
138+
selectable
139+
selectionColor={props.textStyle.selectionColor}
140+
selectionHandleColor={props.textStyle.selectionHandleColor}
141+
style={style}
142+
>
137143
{props.highlighted ? lines : props.content}
138144
</MarkdownTextPrimitive>
139145
);
@@ -174,8 +180,10 @@ function NativeCodeBlock(props: {
174180
justifyContent: "space-between",
175181
}}
176182
>
177-
<Text
183+
<MarkdownTextPrimitive
178184
selectable
185+
selectionColor={props.textStyle.selectionColor}
186+
selectionHandleColor={props.textStyle.selectionHandleColor}
179187
style={{
180188
flex: 1,
181189
color: props.textStyle.mutedColor,
@@ -184,7 +192,7 @@ function NativeCodeBlock(props: {
184192
}}
185193
>
186194
{languageLabel}
187-
</Text>
195+
</MarkdownTextPrimitive>
188196
<CopyTextButton
189197
accessibilityLabel={`Copy ${languageLabel.toLowerCase()} code`}
190198
text={content}
@@ -332,8 +340,10 @@ function NativeMarkdownImage(props: {
332340
}}
333341
/>
334342
{props.node.alt ? (
335-
<Text
343+
<MarkdownTextPrimitive
336344
selectable
345+
selectionColor={props.textStyle.selectionColor}
346+
selectionHandleColor={props.textStyle.selectionHandleColor}
337347
style={{
338348
color: props.textStyle.mutedColor,
339349
fontFamily: props.textStyle.fontFamily,
@@ -342,7 +352,7 @@ function NativeMarkdownImage(props: {
342352
}}
343353
>
344354
{props.node.alt}
345-
</Text>
355+
</MarkdownTextPrimitive>
346356
) : null}
347357
</View>
348358
);

‎apps/mobile/modules/t3-markdown-text/src/NativeMarkdownSelectableText.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ export function NativeMarkdownSelectableText(props: {
338338
}
339339
uiTextView
340340
selectable
341+
selectionColor={props.textStyle.selectionColor}
342+
selectionHandleColor={props.textStyle.selectionHandleColor}
341343
style={{
342344
flexShrink: 1,
343345
minWidth: 0,

0 commit comments

Comments
 (0)