Skip to content

Commit 4d0d8f7

Browse files
lqr131115qrliu97
andauthored
fix: issue #1431 & issue #1432 (#1433)
Co-authored-by: qingruiliu <[email protected]>
1 parent 930c563 commit 4d0d8f7

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

components/input/Input.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,26 @@ const InternalInput: React.ForwardRefRenderFunction<TextInput, InputProps> = (
5252
styles: props.styles,
5353
themeStyles,
5454
})
55-
5655
const timer = React.useRef<any>()
56+
const [focus, setFocus] = React.useState<boolean>()
57+
5758
React.useEffect(() => {
5859
const keyboardHide = Keyboard.addListener('keyboardDidHide', () => {
59-
Keyboard.dismiss()
60+
if(focus){
61+
Keyboard.dismiss()
62+
}
6063
})
6164
return () => {
6265
keyboardHide.remove()
6366
if (timer.current) {
6467
clearTimeout(timer.current)
6568
}
6669
}
67-
}, [])
70+
}, [focus])
6871

6972
const inputRef = React.useRef<TextInput>(null)
7073
React.useImperativeHandle(ref, () => inputRef.current as TextInput)
7174

72-
const [focus, setFocus] = React.useState<boolean>()
73-
7475
// ========================= value prop =========================
7576
const [innerValue, setInnerValue] = useMergedState<string>('', {
7677
value: props.value,

components/input/TextArea/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,19 @@ const TextArea = forwardRef<TextInput, TextAreaProps>((props, ref) => {
2626
// ============================== onLayout ==============================
2727
const [lineHeight, setLineHeight] = useState(0)
2828
const [firstLayoutHeight, setFirstLayoutHeight] = useState(0)
29+
30+
const placeholder = useMemo(() => {
31+
if ([undefined, null, ''].includes(restProps.placeholder)) {
32+
// fix: iOS not show when change placeholder bug
33+
return ' '
34+
}
35+
return restProps.placeholder.toString()
36+
}, [restProps.placeholder])
2937

3038
// ============================== rest TextAreaProps ==============================
3139
const restTextAreaProps: TextAreaProps = useMemo(() => {
3240
if (lineHeight === 0 || firstLayoutHeight === 0) {
3341
return {
34-
placeholder: ' ', // fix: iOS not show when change placeholder bug
3542
onLayout: (e) => {
3643
onLayout?.(e)
3744
if (firstLayoutHeight === 0) {
@@ -83,6 +90,7 @@ const TextArea = forwardRef<TextInput, TextAreaProps>((props, ref) => {
8390
{...restProps}
8491
{...restTextAreaProps}
8592
multiline={true}
93+
placeholder={placeholder}
8694
ref={ref}
8795
/>
8896
)

0 commit comments

Comments
 (0)