From 4a3deddc4805168ce51ce434a6a51385b9a41b6d Mon Sep 17 00:00:00 2001 From: Zaighum Ghazali <35923536+zaighumghazali@users.noreply.github.com> Date: Wed, 9 Aug 2023 20:27:54 +0500 Subject: [PATCH 1/2] Update index.js --- index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 77925dd..3c382d4 100644 --- a/index.js +++ b/index.js @@ -15,7 +15,6 @@ import { Dimensions, TouchableWithoutFeedback, ScrollView, - ViewPropTypes, Platform, } from 'react-native'; import invariant from 'invariant'; @@ -115,7 +114,7 @@ class TagInput extends React.PureComponent, State> { editable: PropTypes.bool, tagColor: PropTypes.string, tagTextColor: PropTypes.string, - tagContainerStyle: ViewPropTypes.style, + tagContainerStyle: PropTypes.object, tagTextStyle: Text.propTypes.style, inputDefaultWidth: PropTypes.number, inputColor: PropTypes.string, @@ -382,8 +381,8 @@ class Tag extends React.PureComponent { removeIndex: PropTypes.func.isRequired, tagColor: PropTypes.string.isRequired, tagTextColor: PropTypes.string.isRequired, - tagContainerStyle: ViewPropTypes.style, - tagTextStyle: Text.propTypes.style, + tagContainerStyle: PropTypes.object, + tagTextStyle: PropTypes.object, showCross: PropTypes.bool.isRequired, }; curPos: ?number = null; From 3c53b469725ffc64364ea558fa26c3b090664791 Mon Sep 17 00:00:00 2001 From: Zaighum Ghazali <35923536+zaighumghazali@users.noreply.github.com> Date: Fri, 18 Aug 2023 16:02:52 +0500 Subject: [PATCH 2/2] Create index.d.ts Added Type Script support --- index.d.ts | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..99206b1 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,93 @@ +declare module 'react-native-tag-input' { + import React, {PureComponent} from 'react' + import {TextInputProps, ScrollView} from 'react-native' + + type StyleObj = Record + + type KeyboardShouldPersistTapsProps = + | 'always' + | 'never' + | 'handled' + | false + | true + + type RequiredProps = { + /** + * An array of tags, which can be any type, as long as labelExtractor below + * can extract a string from it + */ + value: ReadonlyArray + /** + * A handler to be called when array of tags change. The parent should update + * the value prop when this is called if they want to enable removal of tags + */ + onChange: (items: ReadonlyArray) => void + /** + * Function to extract string value for label from item + */ + labelExtractor: (tagData: T) => string | React.ReactNode + /** + * The text currently being displayed in the TextInput following the list of + * tags + */ + text: string + /** + * This callback gets called when the user types in the TextInput. The parent + * should update the text prop when this is called if they want to enable + * input. This is also where any parsing to detect new tags should occur + */ + onChangeText: (text: string) => void + } + + type OptionalProps = { + /** + * If false, text input is not editable and existing tags cannot be removed. + */ + editable: boolean + /** + * Background color of tags + */ + tagColor: string + /** + * Text color of tags + */ + tagTextColor: string + /** + * Styling override for container surrounding tag text + */ + tagContainerStyle?: StyleObj + /** + * Styling override for tag's text component + */ + tagTextStyle?: StyleObj + /** + * Width override for text input's default width when it's empty and showing placeholder + */ + inputDefaultWidth: number + /** + * Color of text input + */ + inputColor: string + /** + * Any misc. TextInput props (autoFocus, placeholder, returnKeyType, etc.) + */ + inputProps?: TextInputProps + /** + * Max height of the tag input on screen (will scroll if max height reached) + */ + maxHeight: number + /** + * Callback that gets passed the new component height when it changes + */ + onHeightChange?: (height: number) => void + /** + * Any ScrollView props (horizontal, showsHorizontalScrollIndicator, etc.) + */ + scrollViewProps?: ScrollView['props'] + } + + type Props = RequiredProps & Partial + + class TagInput extends PureComponent> {} + export default TagInput +}