fix: use entire input box as touch area for focus
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React, { useCallback, useRef } from 'react';
|
||||||
import { Platform, TextInputProps } from 'react-native';
|
import { Platform, TextInput, TextInputProps } from 'react-native';
|
||||||
import styled, { css } from 'styled-components/native';
|
import styled, { css } from 'styled-components/native';
|
||||||
import useDefaultStyles from './Colors';
|
import useDefaultStyles from './Colors';
|
||||||
import { Gap } from './Utility';
|
import { Gap } from './Utility';
|
||||||
@@ -8,7 +8,7 @@ export interface InputProps extends TextInputProps {
|
|||||||
icon?: React.ReactNode
|
icon?: React.ReactNode
|
||||||
}
|
}
|
||||||
|
|
||||||
const Container = styled.View`
|
const Container = styled.Pressable`
|
||||||
margin: 6px 0;
|
margin: 6px 0;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -28,16 +28,19 @@ const InputWrapper = styled.TextInput`
|
|||||||
|
|
||||||
function Input({ icon = null, style, ...rest }: InputProps) {
|
function Input({ icon = null, style, ...rest }: InputProps) {
|
||||||
const defaultStyles = useDefaultStyles();
|
const defaultStyles = useDefaultStyles();
|
||||||
|
const inputRef = useRef<TextInput | null>(null);
|
||||||
|
|
||||||
|
const handlePress = useCallback(() => inputRef.current?.focus(), []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container style={[defaultStyles.input, style]}>
|
<Container style={[defaultStyles.input, style]} onPress={handlePress}>
|
||||||
{icon && (
|
{icon && (
|
||||||
<>
|
<>
|
||||||
{icon}
|
{icon}
|
||||||
<Gap size={8} />
|
<Gap size={8} />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<InputWrapper {...rest} />
|
<InputWrapper {...rest} ref={inputRef} />
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user