|
| 1 | +import * as React from "react"; |
| 2 | +import { |
| 3 | + View, |
| 4 | + Image, |
| 5 | + StyleProp, |
| 6 | + TextInput, |
| 7 | + ViewStyle, |
| 8 | + TextStyle, |
| 9 | + ImageStyle, |
| 10 | + ViewProps, |
| 11 | + TextInputProps, |
| 12 | +} from "react-native"; |
| 13 | +import RNBounceable, { |
| 14 | + IRNBounceableProps, |
| 15 | +} from "@freakycoder/react-native-bounceable"; |
| 16 | +/** |
| 17 | + * ? Local Imports |
| 18 | + */ |
| 19 | +import styles from "./RNTextInput.style"; |
| 20 | + |
| 21 | +const defaultArrowIcon = require("./local-assets/right-arrow.png"); |
| 22 | + |
| 23 | +type CustomStyleProp = StyleProp<ViewStyle> | Array<StyleProp<ViewStyle>>; |
| 24 | + |
| 25 | +export interface ISource { |
| 26 | + source: string | { uri: string }; |
| 27 | +} |
| 28 | + |
| 29 | +interface IRNTextInputProps extends IRNBounceableProps, TextInputProps { |
| 30 | + inputRef?: any; |
| 31 | + ImageComponent?: any; |
| 32 | + placeholder?: string; |
| 33 | + buttonStyle?: ViewStyle; |
| 34 | + textInputStyle?: TextStyle; |
| 35 | + iconImageStyle?: ImageStyle; |
| 36 | + disableButton?: boolean; |
| 37 | + style?: CustomStyleProp; |
| 38 | + onPress?: () => void; |
| 39 | +} |
| 40 | + |
| 41 | +const RNTextInput: React.FC<IRNTextInputProps> = ({ |
| 42 | + style, |
| 43 | + inputRef, |
| 44 | + placeholder, |
| 45 | + buttonStyle, |
| 46 | + textInputStyle, |
| 47 | + iconImageStyle, |
| 48 | + disableButton = false, |
| 49 | + ImageComponent = Image, |
| 50 | + onPress, |
| 51 | + ...props |
| 52 | +}) => { |
| 53 | + const renderContent = () => ( |
| 54 | + <View style={styles.contentContainer}> |
| 55 | + <TextInput |
| 56 | + placeholderTextColor="#ead4ff" |
| 57 | + {...props} |
| 58 | + ref={inputRef} |
| 59 | + placeholder={placeholder} |
| 60 | + style={[styles.textInputStyle, textInputStyle]} |
| 61 | + /> |
| 62 | + {!disableButton && ( |
| 63 | + <RNBounceable style={[styles.buttonStyle, buttonStyle]}> |
| 64 | + <ImageComponent |
| 65 | + source={defaultArrowIcon} |
| 66 | + style={[styles.iconImageStyle, iconImageStyle]} |
| 67 | + /> |
| 68 | + </RNBounceable> |
| 69 | + )} |
| 70 | + </View> |
| 71 | + ); |
| 72 | + |
| 73 | + return ( |
| 74 | + <RNBounceable |
| 75 | + bounceEffect={0.97} |
| 76 | + {...props} |
| 77 | + style={[styles.container, style]} |
| 78 | + onPress={onPress} |
| 79 | + > |
| 80 | + {renderContent()} |
| 81 | + </RNBounceable> |
| 82 | + ); |
| 83 | +}; |
| 84 | + |
| 85 | +export default RNTextInput; |
0 commit comments