mirror of
https://github.com/ikun0014/lx-music-mobile.git
synced 2025-05-23 22:37:41 +08:00
优化设置界面的输入框输入机制
This commit is contained in:
parent
07e4be2b5a
commit
05ecb62907
10
index.js
10
index.js
@ -21,7 +21,7 @@ import { showLyric, onPositionChange } from '@/utils/lyricDesktop'
|
|||||||
import { init as initI18n, supportedLngs } from '@/plugins/i18n'
|
import { init as initI18n, supportedLngs } from '@/plugins/i18n'
|
||||||
import { deviceLanguage, getPlayInfo, toast } from '@/utils/tools'
|
import { deviceLanguage, getPlayInfo, toast } from '@/utils/tools'
|
||||||
import { LIST_ID_PLAY_TEMP } from '@/config/constant'
|
import { LIST_ID_PLAY_TEMP } from '@/config/constant'
|
||||||
import { connect } from '@/plugins/sync'
|
import { connect, SYNC_CODE } from '@/plugins/sync'
|
||||||
|
|
||||||
console.log('starting app...')
|
console.log('starting app...')
|
||||||
|
|
||||||
@ -43,7 +43,13 @@ const init = () => {
|
|||||||
]).then(() => {
|
]).then(() => {
|
||||||
let setting = store.getState().common.setting
|
let setting = store.getState().common.setting
|
||||||
toggleTranslation(setting.player.isShowTranslation)
|
toggleTranslation(setting.player.isShowTranslation)
|
||||||
if (setting.sync.enable) connect()
|
if (setting.sync.enable) {
|
||||||
|
connect().catch(err => {
|
||||||
|
if (err.message == SYNC_CODE.unknownServiceAddress) {
|
||||||
|
store.dispatch(commonAction.setIsEnableSync(false))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
if (setting.desktopLyric.enable) {
|
if (setting.desktopLyric.enable) {
|
||||||
showLyric(
|
showLyric(
|
||||||
setting.desktopLyric.isLock,
|
setting.desktopLyric.isLock,
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
### 优化
|
||||||
|
|
||||||
|
- 优化设置界面的输入框输入机制,现在只要键盘收起即可自动保存输入的内容
|
||||||
|
|
||||||
### 变更
|
### 变更
|
||||||
|
|
||||||
- 不再自动聚焦定时退出、调整位置弹窗内的输入框,这应该可以修复某些设备无法在这两个地方弹出键盘的问题
|
- 不再自动聚焦定时退出、调整位置弹窗内的输入框,这应该可以修复某些设备无法在这两个地方弹出键盘的问题
|
||||||
|
@ -7,4 +7,5 @@ export const SYNC_CODE = {
|
|||||||
getServiceIdFailed: 'Get service id failed',
|
getServiceIdFailed: 'Get service id failed',
|
||||||
connectServiceFailed: 'Connect service failed',
|
connectServiceFailed: 'Connect service failed',
|
||||||
connecting: 'Connecting...',
|
connecting: 'Connecting...',
|
||||||
|
unknownServiceAddress: 'Unknown service address',
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,8 @@ import { SYNC_CODE } from './config'
|
|||||||
|
|
||||||
const handleConnect = async authCode => {
|
const handleConnect = async authCode => {
|
||||||
const hostInfo = await getSyncHost()
|
const hostInfo = await getSyncHost()
|
||||||
if (!hostInfo || !hostInfo.host || !hostInfo.port) throw new Error('Unknown service address')
|
// console.log(hostInfo)
|
||||||
|
if (!hostInfo || !hostInfo.host || !hostInfo.port) throw new Error(SYNC_CODE.unknownServiceAddress)
|
||||||
await disconnect(false)
|
await disconnect(false)
|
||||||
const keyInfo = await handleAuth(hostInfo.host, hostInfo.port, authCode)
|
const keyInfo = await handleAuth(hostInfo.host, hostInfo.port, authCode)
|
||||||
await socketConnect(hostInfo.host, hostInfo.port, keyInfo)
|
await socketConnect(hostInfo.host, hostInfo.port, keyInfo)
|
||||||
@ -34,6 +35,7 @@ const connect = authCode => {
|
|||||||
status: false,
|
status: false,
|
||||||
message: err.message,
|
message: err.message,
|
||||||
}))
|
}))
|
||||||
|
return Promise.reject(err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,11 +121,13 @@ export default memo(() => {
|
|||||||
|
|
||||||
|
|
||||||
const setHost = useCallback(host => {
|
const setHost = useCallback(host => {
|
||||||
|
if (host == hostInfo.host) return
|
||||||
const newHostInfo = { ...hostInfo, host }
|
const newHostInfo = { ...hostInfo, host }
|
||||||
setSyncHost(newHostInfo)
|
setSyncHost(newHostInfo)
|
||||||
setHostInfo(newHostInfo)
|
setHostInfo(newHostInfo)
|
||||||
}, [hostInfo])
|
}, [hostInfo])
|
||||||
const setPort = useCallback(port => {
|
const setPort = useCallback(port => {
|
||||||
|
if (port == hostInfo.host) return
|
||||||
const newHostInfo = { ...hostInfo, port }
|
const newHostInfo = { ...hostInfo, port }
|
||||||
setSyncHost(newHostInfo)
|
setSyncHost(newHostInfo)
|
||||||
setHostInfo(newHostInfo)
|
setHostInfo(newHostInfo)
|
||||||
|
@ -1,33 +1,63 @@
|
|||||||
import React, { memo, useState, useCallback, useEffect, useRef } from 'react'
|
import React, { memo, useState, useCallback, useEffect, useRef } from 'react'
|
||||||
|
|
||||||
import { StyleSheet, View, Text } from 'react-native'
|
import { StyleSheet, View, Text, Keyboard } from 'react-native'
|
||||||
import { useGetter } from '@/store'
|
import { useGetter } from '@/store'
|
||||||
import Input from '@/components/common/Input'
|
import Input from '@/components/common/Input'
|
||||||
|
|
||||||
|
|
||||||
export default memo(({ value, label, onChange, ...props }) => {
|
export default memo(({ value, label, onChange, ...props }) => {
|
||||||
const [text, setText] = useState(value)
|
const [text, setText] = useState(value)
|
||||||
|
const textRef = useRef(value)
|
||||||
const isMountRef = useRef(false)
|
const isMountRef = useRef(false)
|
||||||
|
const inputRef = useRef()
|
||||||
const theme = useGetter('common', 'theme')
|
const theme = useGetter('common', 'theme')
|
||||||
const saveValue = useCallback(() => {
|
const saveValue = useCallback(() => {
|
||||||
onChange && onChange(text, value => {
|
onChange && onChange(text, value => {
|
||||||
if (!isMountRef.current) return
|
if (!isMountRef.current) return
|
||||||
setText(String(value))
|
const newValue = String(value)
|
||||||
|
setText(newValue)
|
||||||
|
textRef.current = newValue
|
||||||
})
|
})
|
||||||
}, [onChange, text])
|
}, [onChange, text])
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
isMountRef.current = true
|
isMountRef.current = true
|
||||||
return () => isMountRef.current = false
|
return () => {
|
||||||
|
isMountRef.current = false
|
||||||
|
}
|
||||||
}, [])
|
}, [])
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (value != text) setText(String(value))
|
const handleKeyboardDidHide = () => {
|
||||||
|
if (!inputRef.current.isFocused()) return
|
||||||
|
onChange && onChange(textRef.current, value => {
|
||||||
|
if (!isMountRef.current) return
|
||||||
|
const newValue = String(value)
|
||||||
|
setText(newValue)
|
||||||
|
textRef.current = newValue
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const keyboardDidHide = Keyboard.addListener('keyboardDidHide', handleKeyboardDidHide)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
keyboardDidHide.remove()
|
||||||
|
}
|
||||||
|
}, [onChange])
|
||||||
|
useEffect(() => {
|
||||||
|
if (value != text) {
|
||||||
|
const newValue = String(value)
|
||||||
|
setText(newValue)
|
||||||
|
textRef.current = newValue
|
||||||
|
}
|
||||||
}, [value])
|
}, [value])
|
||||||
|
const handleSetSelectMode = useCallback(text => {
|
||||||
|
setText(text)
|
||||||
|
textRef.current = text
|
||||||
|
}, [])
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<Text style={{ ...styles.label, color: theme.normal }}>{label}</Text>
|
<Text style={{ ...styles.label, color: theme.normal }}>{label}</Text>
|
||||||
<Input
|
<Input
|
||||||
value={text}
|
value={text}
|
||||||
onChangeText={setText}
|
ref={inputRef}
|
||||||
|
onChangeText={handleSetSelectMode}
|
||||||
style={{ ...styles.input, backgroundColor: theme.secondary40 }}
|
style={{ ...styles.input, backgroundColor: theme.secondary40 }}
|
||||||
{...props}
|
{...props}
|
||||||
onBlur={saveValue}
|
onBlur={saveValue}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user