diff --git a/app/settings.tsx b/app/settings.tsx index d511000..f860834 100644 --- a/app/settings.tsx +++ b/app/settings.tsx @@ -51,6 +51,7 @@ export default function SettingsScreen() { const realMessage = lastMessage.split("_")[0]; handleRemoteInput(realMessage); clearMessage(); // Clear the message after processing + markAsChanged(); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [lastMessage, targetPage]); diff --git a/components/settings/APIConfigSection.tsx b/components/settings/APIConfigSection.tsx index 218b806..14fcaa4 100644 --- a/components/settings/APIConfigSection.tsx +++ b/components/settings/APIConfigSection.tsx @@ -70,10 +70,21 @@ export const APIConfigSection = forwardRef({ + start: 0, + end: 0, + }); + // 当用户手动移动光标或选中文本时,同步到 state(可选) + const onSelectionChange = ({ + nativeEvent: { selection }, + }: any) => { + setSelection(selection); + }; + return ( + {...Platform.isTV || deviceType !== 'tv' ? undefined : { onPress: handlePress }} + > API 地址 @@ -91,7 +102,21 @@ export const APIConfigSection = forwardRef setIsInputFocused(true)} + onFocus={() => { + setIsInputFocused(true); + // 将光标移动到文本末尾 + const end = apiBaseUrl.length; + setSelection({ start: end, end: end }); + // 有时需要延迟一下,让系统先完成 focus 再设置 selection + //(在 Android 上更可靠) + setTimeout(() => { + // 对于受控的 selection 已经生效,这里仅作保险 + inputRef.current?.setNativeProps({ selection: { start: end, end: end } }); + }, 0); + }} + selection={selection} + onSelectionChange={onSelectionChange} // 可选 + onBlur={() => setIsInputFocused(false)} /> diff --git a/components/settings/LiveStreamSection.tsx b/components/settings/LiveStreamSection.tsx index bd1a56d..7d1dd54 100644 --- a/components/settings/LiveStreamSection.tsx +++ b/components/settings/LiveStreamSection.tsx @@ -68,9 +68,21 @@ export const LiveStreamSection = forwardRef({ + start: 0, + end: 0, + }); + // 当用户手动移动光标或选中文本时,同步到 state(可选) + const onSelectionChange = ({ + nativeEvent: { selection }, + }: any) => { + setSelection(selection); + }; + return ( @@ -89,9 +101,23 @@ export const LiveStreamSection = forwardRef setIsInputFocused(true)} + onFocus={() => { + setIsInputFocused(true); + // 将光标移动到文本末尾 + const end = m3uUrl.length; + setSelection({ start: end, end: end }); + // 有时需要延迟一下,让系统先完成 focus 再设置 selection + //(在 Android 上更可靠) + setTimeout(() => { + // 对于受控的 selection 已经生效,这里仅作保险 + inputRef.current?.setNativeProps({ selection: { start: end, end: end } }); + }, 0); + }} + selection={selection} + onSelectionChange={onSelectionChange} // 可选 + onBlur={() => setIsInputFocused(false)} - // onPress={handlePress} + // onPress={handlePress} />