├── .circleci
└── config.yml
├── .editorconfig
├── .gitattributes
├── .gitignore
├── .husky
├── .npmignore
├── commit-msg
└── pre-commit
├── .yarnrc
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── babel.config.js
├── example
├── app.json
├── babel.config.js
├── index.js
├── metro.config.js
├── package.json
├── src
│ ├── App.tsx
│ └── textinput
│ │ ├── example1.tsx
│ │ ├── example2.tsx
│ │ ├── example3.tsx
│ │ ├── example4.tsx
│ │ ├── example5.tsx
│ │ └── example6.tsx
├── webpack.config.js
└── yarn.lock
├── package.json
├── scripts
└── bootstrap.js
├── src
├── AutoComplete
│ ├── icon
│ │ └── close.png
│ ├── index.tsx
│ ├── model.ts
│ └── styles.ts
├── HashtagInput
│ ├── icon
│ │ └── close.png
│ ├── index.tsx
│ ├── model.ts
│ └── styles.ts
├── TagsInput
│ ├── index.tsx
│ ├── model.ts
│ └── styles.ts
├── TextInput
│ ├── icon
│ │ ├── close.png
│ │ ├── eye.png
│ │ └── uneye.png
│ ├── index.tsx
│ ├── model.ts
│ └── styles.ts
└── index.tsx
├── tsconfig.build.json
├── tsconfig.json
└── yarn.lock
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2.1
2 |
3 | executors:
4 | default:
5 | docker:
6 | - image: circleci/node:lts
7 | working_directory: ~/project
8 |
9 | commands:
10 | attach_project:
11 | steps:
12 | - attach_workspace:
13 | at: ~/project
14 |
15 | jobs:
16 | install-dependencies:
17 | executor: default
18 | steps:
19 | - checkout
20 | - attach_project
21 | - restore_cache:
22 | keys:
23 | - dependencies-{{ checksum "package.json" }}
24 | - dependencies-
25 | - restore_cache:
26 | keys:
27 | - dependencies-example-{{ checksum "example/package.json" }}
28 | - dependencies-example-
29 | - run:
30 | name: Install dependencies
31 | command: |
32 | yarn install --cwd example --frozen-lockfile
33 | yarn install --frozen-lockfile
34 | - save_cache:
35 | key: dependencies-{{ checksum "package.json" }}
36 | paths: node_modules
37 | - save_cache:
38 | key: dependencies-example-{{ checksum "example/package.json" }}
39 | paths: example/node_modules
40 | - persist_to_workspace:
41 | root: .
42 | paths: .
43 |
44 | lint:
45 | executor: default
46 | steps:
47 | - attach_project
48 | - run:
49 | name: Lint files
50 | command: |
51 | yarn lint
52 |
53 | typescript:
54 | executor: default
55 | steps:
56 | - attach_project
57 | - run:
58 | name: Typecheck files
59 | command: |
60 | yarn typescript
61 |
62 | unit-tests:
63 | executor: default
64 | steps:
65 | - attach_project
66 | - run:
67 | name: Run unit tests
68 | command: |
69 | yarn test --coverage
70 | - store_artifacts:
71 | path: coverage
72 | destination: coverage
73 |
74 | build-package:
75 | executor: default
76 | steps:
77 | - attach_project
78 | - run:
79 | name: Build package
80 | command: |
81 | yarn prepare
82 |
83 | workflows:
84 | build-and-test:
85 | jobs:
86 | - install-dependencies
87 | - lint:
88 | requires:
89 | - install-dependencies
90 | - typescript:
91 | requires:
92 | - install-dependencies
93 | - unit-tests:
94 | requires:
95 | - install-dependencies
96 | - build-package:
97 | requires:
98 | - install-dependencies
99 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig helps developers define and maintain consistent
2 | # coding styles between different editors and IDEs
3 | # editorconfig.org
4 |
5 | root = true
6 |
7 | [*]
8 |
9 | indent_style = space
10 | indent_size = 2
11 |
12 | end_of_line = lf
13 | charset = utf-8
14 | trim_trailing_whitespace = true
15 | insert_final_newline = true
16 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.pbxproj -text
2 | # specific for windows script files
3 | *.bat text eol=crlf
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # OSX
2 | #
3 | .DS_Store
4 |
5 | # XDE
6 | .expo/
7 |
8 | # VSCode
9 | .vscode/
10 | jsconfig.json
11 |
12 | # Xcode
13 | #
14 | build/
15 | *.pbxuser
16 | !default.pbxuser
17 | *.mode1v3
18 | !default.mode1v3
19 | *.mode2v3
20 | !default.mode2v3
21 | *.perspectivev3
22 | !default.perspectivev3
23 | xcuserdata
24 | *.xccheckout
25 | *.moved-aside
26 | DerivedData
27 | *.hmap
28 | *.ipa
29 | *.xcuserstate
30 | project.xcworkspace
31 |
32 | # Android/IJ
33 | #
34 | .classpath
35 | .cxx
36 | .gradle
37 | .idea
38 | .project
39 | .settings
40 | local.properties
41 | android.iml
42 |
43 | # Cocoapods
44 | #
45 | example/ios/Pods
46 |
47 | # node.js
48 | #
49 | node_modules/
50 | npm-debug.log
51 | yarn-debug.log
52 | yarn-error.log
53 |
54 | # BUCK
55 | buck-out/
56 | \.buckd/
57 | android/app/libs
58 | android/keystores/debug.keystore
59 |
60 | # Expo
61 | .expo/*
62 |
63 | # generated by bob
64 | lib/
65 |
--------------------------------------------------------------------------------
/.husky/.npmignore:
--------------------------------------------------------------------------------
1 | _
2 |
--------------------------------------------------------------------------------
/.husky/commit-msg:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | . "$(dirname "$0")/_/husky.sh"
3 |
4 | yarn commitlint -E HUSKY_GIT_PARAMS
5 |
--------------------------------------------------------------------------------
/.husky/pre-commit:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | . "$(dirname "$0")/_/husky.sh"
3 |
4 | yarn lint && yarn typescript
5 |
--------------------------------------------------------------------------------
/.yarnrc:
--------------------------------------------------------------------------------
1 | # Override Yarn command so we can automatically setup the repo on running `yarn`
2 |
3 | yarn-path "scripts/bootstrap.js"
4 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project.
4 |
5 | ## Development workflow
6 |
7 | To get started with the project, run `yarn` in the root directory to install the required dependencies for each package:
8 |
9 | ```sh
10 | yarn
11 | ```
12 |
13 | > While it's possible to use [`npm`](https://github.com/npm/cli), the tooling is built around [`yarn`](https://classic.yarnpkg.com/), so you'll have an easier time if you use `yarn` for development.
14 |
15 | While developing, you can run the [example app](/example/) to test your changes. Any changes you make in your library's JavaScript code will be reflected in the example app without a rebuild. If you change any native code, then you'll need to rebuild the example app.
16 |
17 | To start the packager:
18 |
19 | ```sh
20 | yarn example start
21 | ```
22 |
23 | To run the example app on Android:
24 |
25 | ```sh
26 | yarn example android
27 | ```
28 |
29 | To run the example app on iOS:
30 |
31 | ```sh
32 | yarn example ios
33 | ```
34 |
35 | To run the example app on Web:
36 |
37 | ```sh
38 | yarn example web
39 | ```
40 |
41 | Make sure your code passes TypeScript and ESLint. Run the following to verify:
42 |
43 | ```sh
44 | yarn typescript
45 | yarn lint
46 | ```
47 |
48 | To fix formatting errors, run the following:
49 |
50 | ```sh
51 | yarn lint --fix
52 | ```
53 |
54 | Remember to add tests for your change if possible. Run the unit tests by:
55 |
56 | ```sh
57 | yarn test
58 | ```
59 |
60 | ### Commit message convention
61 |
62 | We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages:
63 |
64 | - `fix`: bug fixes, e.g. fix crash due to deprecated method.
65 | - `feat`: new features, e.g. add new method to the module.
66 | - `refactor`: code refactor, e.g. migrate from class components to hooks.
67 | - `docs`: changes into documentation, e.g. add usage example for the module..
68 | - `test`: adding or updating tests, e.g. add integration tests using detox.
69 | - `chore`: tooling changes, e.g. change CI config.
70 |
71 | Our pre-commit hooks verify that your commit message matches this format when committing.
72 |
73 | ### Linting and tests
74 |
75 | [ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/)
76 |
77 | We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing.
78 |
79 | Our pre-commit hooks verify that the linter and tests pass when committing.
80 |
81 | ### Publishing to npm
82 |
83 | We use [release-it](https://github.com/release-it/release-it) to make it easier to publish new versions. It handles common tasks like bumping version based on semver, creating tags and releases etc.
84 |
85 | To publish new versions, run the following:
86 |
87 | ```sh
88 | yarn release
89 | ```
90 |
91 | ### Scripts
92 |
93 | The `package.json` file contains various scripts for common tasks:
94 |
95 | - `yarn bootstrap`: setup project by installing all dependencies and pods.
96 | - `yarn typescript`: type-check files with TypeScript.
97 | - `yarn lint`: lint files with ESLint.
98 | - `yarn test`: run unit tests with Jest.
99 | - `yarn example start`: start the Metro server for the example app.
100 | - `yarn example android`: run the example app on Android.
101 | - `yarn example ios`: run the example app on iOS.
102 |
103 | ### Sending a pull request
104 |
105 | > **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github).
106 |
107 | When you're sending a pull request:
108 |
109 | - Prefer small pull requests focused on one change.
110 | - Verify that linters and tests are passing.
111 | - Review the documentation to make sure it looks good.
112 | - Follow the pull request template when opening a pull request.
113 | - For pull requests that change the API or implementation, discuss with maintainers first by opening an issue.
114 |
115 | ## Code of Conduct
116 |
117 | ### Our Pledge
118 |
119 | We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
120 |
121 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
122 |
123 | ### Our Standards
124 |
125 | Examples of behavior that contributes to a positive environment for our community include:
126 |
127 | - Demonstrating empathy and kindness toward other people
128 | - Being respectful of differing opinions, viewpoints, and experiences
129 | - Giving and gracefully accepting constructive feedback
130 | - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
131 | - Focusing on what is best not just for us as individuals, but for the overall community
132 |
133 | Examples of unacceptable behavior include:
134 |
135 | - The use of sexualized language or imagery, and sexual attention or
136 | advances of any kind
137 | - Trolling, insulting or derogatory comments, and personal or political attacks
138 | - Public or private harassment
139 | - Publishing others' private information, such as a physical or email
140 | address, without their explicit permission
141 | - Other conduct which could reasonably be considered inappropriate in a
142 | professional setting
143 |
144 | ### Enforcement Responsibilities
145 |
146 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
147 |
148 | Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
149 |
150 | ### Scope
151 |
152 | This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
153 |
154 | ### Enforcement
155 |
156 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [INSERT CONTACT METHOD]. All complaints will be reviewed and investigated promptly and fairly.
157 |
158 | All community leaders are obligated to respect the privacy and security of the reporter of any incident.
159 |
160 | ### Enforcement Guidelines
161 |
162 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
163 |
164 | #### 1. Correction
165 |
166 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
167 |
168 | **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
169 |
170 | #### 2. Warning
171 |
172 | **Community Impact**: A violation through a single incident or series of actions.
173 |
174 | **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
175 |
176 | #### 3. Temporary Ban
177 |
178 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
179 |
180 | **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
181 |
182 | #### 4. Permanent Ban
183 |
184 | **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
185 |
186 | **Consequence**: A permanent ban from any sort of public interaction within the community.
187 |
188 | ### Attribution
189 |
190 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
191 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
192 |
193 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
194 |
195 | [homepage]: https://www.contributor-covenant.org
196 |
197 | For answers to common questions about this code of conduct, see the FAQ at
198 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
199 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Hoa Phan
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # react-native-element-textinput
2 | A react-native TextInput, TagsInput and AutoComplete component easy to customize for both iOS and Android.
3 |
4 | ## Features
5 | * TextInput, TagsInput and AutoComplete in one package
6 | * Easy to use
7 | * Consistent look and feel on iOS and Android
8 | * Customizable font size, colors and animation duration
9 | * Implemented with typescript
10 |
11 | ## Getting started
12 | ```js
13 | npm install react-native-element-textinput --save
14 | ```
15 | or
16 |
17 | ```js
18 | yarn add react-native-element-textinput
19 | ```
20 |
21 | #### Source code demo
22 | - [react-native-template-components](https://github.com/hoaphantn7604/react-native-template-components) A beautiful template for React Native.
23 |
24 | ### Demo
25 | 
26 |
27 | #### TextInput extends TextInputProps
28 | | Props | Params | isRequire | default |
29 | | ------------------ | -------------------- | --------- | ---------------------------------- |
30 | | mode | default or numeric or password |No | Switch mode textinput |
31 | | style | ViewStyle | No | Styling for container view |
32 | | label | String | No | Label for textinput |
33 | | labelStyle | TextStyle | No | Styling for label text |
34 | | placeholderStyle | TextStyle | No | Styling for placeholderStyle text |
35 | | inputStyle | TextStyle | No | Styling for input view |
36 | | textError | String | No | Text error |
37 | | textErrorStyle | TextStyle | No | Styling for text error |
38 | | showIcon | Boolean | No | Show or hide icon clear text |
39 | | iconStyle | ImageStyle | No | Styling for icon clear text |
40 | | focusColor | String | No | Color when focus to textinput |
41 | | fontFamily | String | No | Customize font style |
42 | | renderLeftIcon | () => JSX.Element | No | Customize left icon for textinput |
43 | | renderRightIcon | () => JSX.Element | No | Customize right icon for textinput |
44 |
45 | #### HashtagInput extends TextInputProps
46 | | Props | Params | isRequire | default |
47 | | ------------------ | -------------------- | --------- | ---------------------------------- |
48 | | style | ViewStyle | No | Styling for container view |
49 | | label | String | No | Label for textinput |
50 | | labelStyle | TextStyle | No | Styling for label text |
51 | | placeholderStyle | TextStyle | No | Styling for placeholderStyle text |
52 | | inputStyle | TextStyle | No | Styling for input view |
53 | | textError | String | No | Text error |
54 | | textErrorStyle | TextStyle | No | Styling for text error |
55 | | showIcon | Boolean | No | Show or hide icon clear text |
56 | | iconStyle | ImageStyle | No | Styling for icon clear text |
57 | | focusColor | String | No | Color when focus to textinput |
58 | | fontFamily | String | No | Customize font style |
59 | | renderLeftIcon | () => JSX.Element | No | Customize left icon for textinput |
60 | | renderRightIcon | () => JSX.Element | No | Customize right icon for textinput |
61 | | data | String[] | No | Data is a plain array |
62 | | hashtagStyle | ViewStyle | No | Styling for hashtash container view|
63 | | hashtagTextStyle | TextStyle | No | Styling for hashtag text |
64 | | onChangeValue | (string[]) => void | No | Callback that is called when submit value |
65 | | renderHashtagItem | (item, unSelect?: () => void) => JSX.Element | No | Takes an item from data and renders it into the list selected |
66 |
67 | #### TagsInput extends TextInputProps
68 | | Props | Params | isRequire | default |
69 | | ------------------ | -------------------- | --------- | ---------------------------------- |
70 | | style | ViewStyle | No | Styling for container view |
71 | | label | String | No | Label for textinput |
72 | | labelStyle | TextStyle | No | Styling for label text |
73 | | placeholderStyle | TextStyle | No | Styling for placeholderStyle text |
74 | | inputStyle | TextStyle | No | Styling for input view |
75 | | textError | String | No | Text error |
76 | | textErrorStyle | TextStyle | No | Styling for text error |
77 | | showIcon | Boolean | No | Show or hide icon clear text |
78 | | iconStyle | ImageStyle | No | Styling for icon clear text |
79 | | focusColor | String | No | Color when focus to textinput |
80 | | fontFamily | String | No | Customize font style |
81 | | renderLeftIcon | () => JSX.Element | No | Customize left icon for textinput |
82 | | renderRightIcon | () => JSX.Element | No | Customize right icon for textinput |
83 | | data | String[] | No | Data is a plain array |
84 | | tagsStyle | ViewStyle | No | Styling for hashtash container view|
85 | | tagsTextStyle | TextStyle | No | Styling for hashtag text |
86 | | onChangeValue | (string[]) => void | No | Callback that is called when submit value |
87 | | renderTagsItem | (item, unSelect?: () => void) => JSX.Element | No | Takes an item from data and renders it into the list selected |
88 |
89 |
90 |
91 |
92 | #### AutoComplete extends TextInputProps
93 | | Props | Params | isRequire | default |
94 | | ------------------ | -----------------------------| --------- | ---------------------------------- |
95 | | data | String[] | No | Data is a plain array |
96 | | style | ViewStyle | No | Styling for container view |
97 | | label | String | No | Label for textinput |
98 | | labelStyle | TextStyle | No | Styling for label text |
99 | | placeholderStyle | TextStyle | No | Styling for placeholderStyle text |
100 | | inputStyle | TextStyle | No | Styling for input view |
101 | | textError | String | No | Text error |
102 | | textErrorStyle | TextStyle | No | Styling for text error |
103 | | showIcon | Boolean | No | Show or hide icon clear text |
104 | | iconStyle | ImageStyle | No | Styling for icon clear text |
105 | | focusColor | String | No | Color when focus to textinput |
106 | | fontFamily | String | No | Customize font style |
107 | | renderLeftIcon | () => JSX.Element | No | Customize left icon for textinput |
108 | | renderRightIcon | () => JSX.Element | No | Customize right icon for textinput |
109 | | renderItem | (item:string) => JSX.Element | No | Takes an item from data and renders it into the list |
110 |
111 |
112 | ### Example 1
113 | 
114 | ```js
115 | import React, { useState } from 'react';
116 | import { StyleSheet, View } from 'react-native';
117 | import { TextInput } from 'react-native-element-textinput';
118 |
119 | const TextInputComponent = () => {
120 | const [value, setValue] = useState('');
121 |
122 | return (
123 |
124 | {
136 | setValue(text);
137 | }}
138 | />
139 |
140 | );
141 | };
142 |
143 | export default TextInputComponent;
144 |
145 | const styles = StyleSheet.create({
146 | container: {
147 | padding: 16,
148 | },
149 | input: {
150 | height: 55,
151 | paddingHorizontal: 12,
152 | borderRadius: 8,
153 | borderWidth: 0.5,
154 | borderColor: '#DDDDDD',
155 | },
156 | inputStyle: { fontSize: 16 },
157 | labelStyle: {
158 | fontSize: 14,
159 | position: 'absolute',
160 | top: -10,
161 | backgroundColor: 'white',
162 | paddingHorizontal: 4,
163 | marginLeft: -4,
164 | },
165 | placeholderStyle: { fontSize: 16 },
166 | textErrorStyle: { fontSize: 16 },
167 | });
168 | ```
169 |
170 | ### Example 2
171 | 
172 | ```js
173 | import React, { useState } from 'react';
174 | import { StyleSheet, View } from 'react-native';
175 | import { TextInput } from 'react-native-element-textinput';
176 |
177 | const TextInputComponent = () => {
178 | const [value, setValue] = useState('');
179 |
180 | return (
181 |
182 | {
193 | setValue(text);
194 | }}
195 | />
196 |
197 | );
198 | };
199 |
200 | export default TextInputComponent;
201 |
202 | const styles = StyleSheet.create({
203 | container: {
204 | padding: 16,
205 | },
206 | input: {
207 | height: 55,
208 | paddingHorizontal: 12,
209 | borderRadius: 8,
210 | backgroundColor: 'white',
211 | shadowColor: '#000',
212 | shadowOffset: {
213 | width: 0,
214 | height: 1,
215 | },
216 | shadowOpacity: 0.2,
217 | shadowRadius: 1.41,
218 | elevation: 2,
219 | },
220 | inputStyle: { fontSize: 16 },
221 | labelStyle: { fontSize: 14 },
222 | placeholderStyle: { fontSize: 16 },
223 | textErrorStyle: { fontSize: 16 },
224 | });
225 | ```
226 |
227 | ### Example 3
228 | 
229 | ```js
230 | import React, { useState } from 'react';
231 | import { StyleSheet, View } from 'react-native';
232 | import { TextInput } from 'react-native-element-textinput';
233 |
234 | const TextInputComponent = () => {
235 | const [value, setValue] = useState('');
236 |
237 | return (
238 |
239 | {
251 | setValue(text);
252 | }}
253 | />
254 |
255 | );
256 | };
257 |
258 | export default TextInputComponent;
259 |
260 | const styles = StyleSheet.create({
261 | container: {
262 | padding: 16,
263 | },
264 | input: {
265 | height: 55,
266 | paddingHorizontal: 12,
267 | borderRadius: 8,
268 | backgroundColor: 'white',
269 | shadowColor: '#000',
270 | shadowOffset: {
271 | width: 0,
272 | height: 1,
273 | },
274 | shadowOpacity: 0.2,
275 | shadowRadius: 1.41,
276 | elevation: 2,
277 | },
278 | inputStyle: { fontSize: 16 },
279 | labelStyle: { fontSize: 14 },
280 | placeholderStyle: { fontSize: 16 },
281 | textErrorStyle: { fontSize: 16 },
282 | });
283 | ```
284 |
285 | ### Example 4
286 | 
287 | ```js
288 | import React, { useState } from 'react';
289 | import { StyleSheet, View } from 'react-native';
290 | import { HashtagInput } from 'react-native-element-textinput';
291 |
292 | const TextInputComponent = () => {
293 | const [value, setValue] = useState([]);
294 |
295 | return (
296 |
297 | {
309 | setValue(value);
310 | }}
311 | />
312 |
313 | );
314 | };
315 |
316 | export default TextInputComponent;
317 |
318 | const styles = StyleSheet.create({
319 | container: {
320 | padding: 16,
321 | },
322 | input: {
323 | height: 55,
324 | paddingHorizontal: 12,
325 | borderRadius: 8,
326 | backgroundColor: 'white',
327 | shadowColor: '#000',
328 | shadowOffset: {
329 | width: 0,
330 | height: 1,
331 | },
332 | shadowOpacity: 0.2,
333 | shadowRadius: 1.41,
334 | elevation: 2,
335 | },
336 | inputStyle: { fontSize: 16 },
337 | labelStyle: { fontSize: 14 },
338 | placeholderStyle: { fontSize: 16 },
339 | textErrorStyle: { fontSize: 16 },
340 | hashtagStyle: {
341 | borderWidth: 0,
342 | borderRadius: 16,
343 | padding: 8,
344 | backgroundColor: 'white',
345 | shadowColor: '#000',
346 | shadowOffset: {
347 | width: 0,
348 | height: 1,
349 | },
350 | shadowOpacity: 0.2,
351 | shadowRadius: 1.41,
352 | elevation: 2,
353 | },
354 | hashtagTextStyle: {
355 | fontSize: 16,
356 | },
357 | });
358 | ```
359 |
360 | ### Example 5
361 | 
362 | ```js
363 | import React, { useState } from 'react';
364 | import { StyleSheet, View } from 'react-native';
365 | import { TagsInput } from 'react-native-element-textinput';
366 |
367 | const TextInputComponent = () => {
368 | const [value, setValue] = useState([]);
369 |
370 | return (
371 |
372 | {
385 | setValue(value);
386 | }}
387 | />
388 |
389 | );
390 | };
391 |
392 | export default TextInputComponent;
393 |
394 | const styles = StyleSheet.create({
395 | container: {
396 | padding: 16,
397 | },
398 | input: {
399 | paddingHorizontal: 12,
400 | borderRadius: 8,
401 | backgroundColor: 'white',
402 | shadowColor: '#000',
403 | shadowOffset: {
404 | width: 0,
405 | height: 1,
406 | },
407 | shadowOpacity: 0.2,
408 | shadowRadius: 1.41,
409 | elevation: 2,
410 | },
411 | inputStyle: {
412 | fontSize: 16,
413 | minWidth: 80,
414 | },
415 | labelStyle: {
416 | fontSize: 14,
417 | position: 'absolute',
418 | top: -10,
419 | backgroundColor: 'white',
420 | paddingHorizontal: 4,
421 | marginLeft: -4,
422 | },
423 | placeholderStyle: { fontSize: 16 },
424 | textErrorStyle: { fontSize: 16 },
425 | tagsStyle: {
426 | borderWidth: 0,
427 | borderRadius: 16,
428 | padding: 8,
429 | backgroundColor: 'white',
430 | shadowColor: '#000',
431 | shadowOffset: {
432 | width: 0,
433 | height: 1,
434 | },
435 | shadowOpacity: 0.2,
436 | shadowRadius: 1.41,
437 | elevation: 2,
438 | },
439 | tagsTextStyle: {
440 | fontSize: 16,
441 | },
442 | });
443 | ```
444 |
445 | ### Example 6
446 | 
447 | ```js
448 | import React, { useState } from 'react';
449 | import { StyleSheet, View } from 'react-native';
450 | import { AutoComplete } from 'react-native-element-textinput';
451 |
452 | const TextInputComponent = () => {
453 | const [value, setValue] = useState('');
454 |
455 | return (
456 |
457 | {
469 | setValue(e);
470 | }}
471 | />
472 |
473 | );
474 | };
475 |
476 | export default TextInputComponent;
477 |
478 | const styles = StyleSheet.create({
479 | container: {
480 | padding: 16,
481 | },
482 | input: {
483 | height: 55,
484 | paddingHorizontal: 12,
485 | borderRadius: 8,
486 | backgroundColor: 'white',
487 | shadowColor: '#000',
488 | shadowOffset: {
489 | width: 0,
490 | height: 1,
491 | },
492 | shadowOpacity: 0.2,
493 | shadowRadius: 1.41,
494 | elevation: 2,
495 | },
496 | inputStyle: { fontSize: 16 },
497 | labelStyle: { fontSize: 14 },
498 | placeholderStyle: { fontSize: 16 },
499 | textErrorStyle: { fontSize: 16 },
500 | });
501 | ```
502 |
503 | [
](https://www.youtube.com/channel/UCemCdKGzUgbfsLeGFOvbVEw?sub_confirmation=1)
504 |
--------------------------------------------------------------------------------
/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: ['module:metro-react-native-babel-preset'],
3 | };
4 |
--------------------------------------------------------------------------------
/example/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-element-textinput-example",
3 | "displayName": "ElementTextinput Example",
4 | "expo": {
5 | "name": "react-native-element-textinput-example",
6 | "slug": "react-native-element-textinput-example",
7 | "description": "Example app for react-native-element-textinput",
8 | "privacy": "public",
9 | "version": "1.0.0",
10 | "platforms": [
11 | "ios",
12 | "android",
13 | "web"
14 | ],
15 | "ios": {
16 | "supportsTablet": true
17 | },
18 | "assetBundlePatterns": [
19 | "**/*"
20 | ]
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/example/babel.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const pak = require('../package.json');
3 |
4 | module.exports = function (api) {
5 | api.cache(true);
6 |
7 | return {
8 | presets: ['babel-preset-expo'],
9 | plugins: [
10 | [
11 | 'module-resolver',
12 | {
13 | extensions: ['.tsx', '.ts', '.js', '.json'],
14 | alias: {
15 | // For development, we want to alias the library to the source
16 | [pak.name]: path.join(__dirname, '..', pak.source),
17 | },
18 | },
19 | ],
20 | ],
21 | };
22 | };
23 |
--------------------------------------------------------------------------------
/example/index.js:
--------------------------------------------------------------------------------
1 | import { registerRootComponent } from 'expo';
2 |
3 | import App from './src/App';
4 |
5 | // registerRootComponent calls AppRegistry.registerComponent('main', () => App);
6 | // It also ensures that whether you load the app in the Expo client or in a native build,
7 | // the environment is set up appropriately
8 | registerRootComponent(App);
9 |
--------------------------------------------------------------------------------
/example/metro.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const blacklist = require('metro-config/src/defaults/blacklist');
3 | const escape = require('escape-string-regexp');
4 | const pak = require('../package.json');
5 |
6 | const root = path.resolve(__dirname, '..');
7 |
8 | const modules = Object.keys({
9 | ...pak.peerDependencies,
10 | });
11 |
12 | module.exports = {
13 | projectRoot: __dirname,
14 | watchFolders: [root],
15 |
16 | // We need to make sure that only one version is loaded for peerDependencies
17 | // So we blacklist them at the root, and alias them to the versions in example's node_modules
18 | resolver: {
19 | blacklistRE: blacklist(
20 | modules.map(
21 | (m) =>
22 | new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`)
23 | )
24 | ),
25 |
26 | extraNodeModules: modules.reduce((acc, name) => {
27 | acc[name] = path.join(__dirname, 'node_modules', name);
28 | return acc;
29 | }, {}),
30 | },
31 |
32 | transformer: {
33 | getTransformOptions: async () => ({
34 | transform: {
35 | experimentalImportSupport: false,
36 | inlineRequires: true,
37 | },
38 | }),
39 | },
40 | };
41 |
--------------------------------------------------------------------------------
/example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-element-textinput-example",
3 | "description": "Example app for react-native-element-textinput",
4 | "version": "0.0.1",
5 | "private": true,
6 | "main": "index",
7 | "scripts": {
8 | "android": "expo start --android",
9 | "ios": "expo start --ios",
10 | "web": "expo start --web",
11 | "start": "expo start",
12 | "test": "jest"
13 | },
14 | "dependencies": {
15 | "expo": "^42.0.0",
16 | "expo-splash-screen": "~0.11.2",
17 | "react": "16.13.1",
18 | "react-dom": "16.13.1",
19 | "react-native": "0.63.4",
20 | "react-native-unimodules": "~0.14.5",
21 | "react-native-web": "~0.13.12"
22 | },
23 | "devDependencies": {
24 | "@babel/core": "~7.9.0",
25 | "@babel/runtime": "^7.9.6",
26 | "babel-plugin-module-resolver": "^4.0.0",
27 | "babel-preset-expo": "8.3.0",
28 | "expo-cli": "^4.0.13"
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/example/src/App.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { StyleSheet, View } from 'react-native';
3 | import { ScrollView } from 'react-native-virtualized-view';
4 | import Example1 from './textinput/example1';
5 | import Example2 from './textinput/example2';
6 | import Example3 from './textinput/example3';
7 | import Example4 from './textinput/example4';
8 | import Example5 from './textinput/example5';
9 | import Example6 from './textinput/example6';
10 |
11 | const TextInputScreen = (_props: any) => {
12 | return (
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | );
24 | };
25 |
26 | export default TextInputScreen;
27 |
28 | const styles = StyleSheet.create({
29 | container: {
30 | flex: 1,
31 | backgroundColor: 'white',
32 | marginTop: 50,
33 | },
34 | });
35 |
--------------------------------------------------------------------------------
/example/src/textinput/example1.tsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 | import { StyleSheet, View } from 'react-native';
3 | import { TextInput } from 'react-native-element-textinput';
4 |
5 | const TextInputComponent = () => {
6 | const [value, setValue] = useState('');
7 |
8 | return (
9 |
10 | {
22 | setValue(text);
23 | }}
24 | />
25 |
26 | );
27 | };
28 |
29 | export default TextInputComponent;
30 |
31 | const styles = StyleSheet.create({
32 | container: {
33 | padding: 16,
34 | },
35 | input: {
36 | height: 55,
37 | paddingHorizontal: 12,
38 | borderRadius: 8,
39 | borderWidth: 0.5,
40 | borderColor: '#DDDDDD',
41 | },
42 | inputStyle: { fontSize: 16 },
43 | labelStyle: {
44 | fontSize: 14,
45 | position: 'absolute',
46 | top: -10,
47 | backgroundColor: 'white',
48 | paddingHorizontal: 4,
49 | marginLeft: -4,
50 | },
51 | placeholderStyle: { fontSize: 16 },
52 | textErrorStyle: { fontSize: 16 },
53 | });
54 |
--------------------------------------------------------------------------------
/example/src/textinput/example2.tsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 | import { StyleSheet, View } from 'react-native';
3 | import { TextInput } from 'react-native-element-textinput';
4 |
5 | const TextInputComponent = () => {
6 | const [value, setValue] = useState('');
7 |
8 | return (
9 |
10 | {
21 | setValue(text);
22 | }}
23 | />
24 |
25 | );
26 | };
27 |
28 | export default TextInputComponent;
29 |
30 | const styles = StyleSheet.create({
31 | container: {
32 | padding: 16,
33 | },
34 | input: {
35 | height: 55,
36 | paddingHorizontal: 12,
37 | borderRadius: 8,
38 | backgroundColor: 'white',
39 | shadowColor: '#000',
40 | shadowOffset: {
41 | width: 0,
42 | height: 1,
43 | },
44 | shadowOpacity: 0.2,
45 | shadowRadius: 1.41,
46 | elevation: 2,
47 | },
48 | inputStyle: { fontSize: 16 },
49 | labelStyle: { fontSize: 14 },
50 | placeholderStyle: { fontSize: 16 },
51 | textErrorStyle: { fontSize: 16 },
52 | });
53 |
--------------------------------------------------------------------------------
/example/src/textinput/example3.tsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 | import { StyleSheet, View } from 'react-native';
3 | import { TextInput } from 'react-native-element-textinput';
4 |
5 | const TextInputComponent = () => {
6 | const [value, setValue] = useState('');
7 |
8 | return (
9 |
10 | {
22 | setValue(text);
23 | }}
24 | />
25 |
26 | );
27 | };
28 |
29 | export default TextInputComponent;
30 |
31 | const styles = StyleSheet.create({
32 | container: {
33 | padding: 16,
34 | },
35 | input: {
36 | height: 55,
37 | paddingHorizontal: 12,
38 | borderRadius: 8,
39 | backgroundColor: 'white',
40 | shadowColor: '#000',
41 | shadowOffset: {
42 | width: 0,
43 | height: 1,
44 | },
45 | shadowOpacity: 0.2,
46 | shadowRadius: 1.41,
47 | elevation: 2,
48 | },
49 | inputStyle: { fontSize: 16 },
50 | labelStyle: { fontSize: 14 },
51 | placeholderStyle: { fontSize: 16 },
52 | textErrorStyle: { fontSize: 16 },
53 | });
54 |
--------------------------------------------------------------------------------
/example/src/textinput/example4.tsx:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-shadow */
2 | import React, { useState } from 'react';
3 | import { StyleSheet, View } from 'react-native';
4 | import { HashtagInput } from 'react-native-element-textinput';
5 |
6 | const TextInputComponent = () => {
7 | const [value, setValue] = useState([]);
8 |
9 | return (
10 |
11 | {
23 | setValue(value);
24 | }}
25 | />
26 |
27 | );
28 | };
29 |
30 | export default TextInputComponent;
31 |
32 | const styles = StyleSheet.create({
33 | container: {
34 | padding: 16,
35 | },
36 | input: {
37 | height: 55,
38 | paddingHorizontal: 12,
39 | borderRadius: 8,
40 | backgroundColor: 'white',
41 | shadowColor: '#000',
42 | shadowOffset: {
43 | width: 0,
44 | height: 1,
45 | },
46 | shadowOpacity: 0.2,
47 | shadowRadius: 1.41,
48 | elevation: 2,
49 | },
50 | inputStyle: { fontSize: 16 },
51 | labelStyle: { fontSize: 14 },
52 | placeholderStyle: { fontSize: 16 },
53 | textErrorStyle: { fontSize: 16 },
54 | hashtagStyle: {
55 | borderWidth: 0,
56 | borderRadius: 16,
57 | padding: 8,
58 | backgroundColor: 'white',
59 | shadowColor: '#000',
60 | shadowOffset: {
61 | width: 0,
62 | height: 1,
63 | },
64 | shadowOpacity: 0.2,
65 | shadowRadius: 1.41,
66 | elevation: 2,
67 | },
68 | hashtagTextStyle: {
69 | fontSize: 16,
70 | },
71 | });
72 |
--------------------------------------------------------------------------------
/example/src/textinput/example5.tsx:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-shadow */
2 | import React, { useState } from 'react';
3 | import { StyleSheet, View } from 'react-native';
4 | import { TagsInput } from 'react-native-element-textinput';
5 |
6 | const TextInputComponent = () => {
7 | const [value, setValue] = useState([]);
8 |
9 | return (
10 |
11 | {
24 | setValue(value);
25 | }}
26 | />
27 |
28 | );
29 | };
30 |
31 | export default TextInputComponent;
32 |
33 | const styles = StyleSheet.create({
34 | container: {
35 | padding: 16,
36 | },
37 | input: {
38 | paddingHorizontal: 12,
39 | borderRadius: 8,
40 | backgroundColor: 'white',
41 | shadowColor: '#000',
42 | shadowOffset: {
43 | width: 0,
44 | height: 1,
45 | },
46 | shadowOpacity: 0.2,
47 | shadowRadius: 1.41,
48 | elevation: 2,
49 | },
50 | inputStyle: {
51 | fontSize: 16,
52 | minWidth: 80,
53 | },
54 | labelStyle: {
55 | fontSize: 14,
56 | position: 'absolute',
57 | top: -10,
58 | backgroundColor: 'white',
59 | paddingHorizontal: 4,
60 | marginLeft: -4,
61 | },
62 | placeholderStyle: { fontSize: 16 },
63 | textErrorStyle: { fontSize: 16 },
64 | tagsStyle: {
65 | borderWidth: 0,
66 | borderRadius: 16,
67 | padding: 8,
68 | backgroundColor: 'white',
69 | shadowColor: '#000',
70 | shadowOffset: {
71 | width: 0,
72 | height: 1,
73 | },
74 | shadowOpacity: 0.2,
75 | shadowRadius: 1.41,
76 | elevation: 2,
77 | },
78 | tagsTextStyle: {
79 | fontSize: 16,
80 | },
81 | });
82 |
--------------------------------------------------------------------------------
/example/src/textinput/example6.tsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 | import { StyleSheet, View } from 'react-native';
3 | import { AutoComplete } from 'react-native-element-textinput';
4 |
5 | const TextInputComponent = () => {
6 | const [value, setValue] = useState('');
7 |
8 | return (
9 |
10 | {
22 | setValue(e);
23 | }}
24 | />
25 |
26 | );
27 | };
28 |
29 | export default TextInputComponent;
30 |
31 | const styles = StyleSheet.create({
32 | container: {
33 | padding: 16,
34 | },
35 | input: {
36 | height: 55,
37 | paddingHorizontal: 12,
38 | borderRadius: 8,
39 | backgroundColor: 'white',
40 | shadowColor: '#000',
41 | shadowOffset: {
42 | width: 0,
43 | height: 1,
44 | },
45 | shadowOpacity: 0.2,
46 | shadowRadius: 1.41,
47 | elevation: 2,
48 | },
49 | inputStyle: { fontSize: 16 },
50 | labelStyle: { fontSize: 14 },
51 | placeholderStyle: { fontSize: 16 },
52 | textErrorStyle: { fontSize: 16 },
53 | });
54 |
--------------------------------------------------------------------------------
/example/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const createExpoWebpackConfigAsync = require('@expo/webpack-config');
3 | const { resolver } = require('./metro.config');
4 |
5 | const root = path.resolve(__dirname, '..');
6 | const node_modules = path.join(__dirname, 'node_modules');
7 |
8 | module.exports = async function (env, argv) {
9 | const config = await createExpoWebpackConfigAsync(env, argv);
10 |
11 | config.module.rules.push({
12 | test: /\.(js|jsx|ts|tsx)$/,
13 | include: path.resolve(root, 'src'),
14 | use: 'babel-loader',
15 | });
16 |
17 | // We need to make sure that only one version is loaded for peerDependencies
18 | // So we alias them to the versions in example's node_modules
19 | Object.assign(config.resolve.alias, {
20 | ...resolver.extraNodeModules,
21 | 'react-native-web': path.join(node_modules, 'react-native-web'),
22 | });
23 |
24 | return config;
25 | };
26 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-element-textinput",
3 | "version": "2.2.0",
4 | "description": "A react-native TextInput, TagsInput and AutoComplete component easy to customize for both iOS and Android.",
5 | "main": "lib/commonjs/index",
6 | "module": "lib/module/index",
7 | "types": "lib/typescript/index.d.ts",
8 | "react-native": "src/index",
9 | "source": "src/index",
10 | "files": [
11 | "src",
12 | "lib",
13 | "android",
14 | "ios",
15 | "cpp",
16 | "react-native-element-textinput.podspec",
17 | "!lib/typescript/example",
18 | "!android/build",
19 | "!ios/build",
20 | "!**/__tests__",
21 | "!**/__fixtures__",
22 | "!**/__mocks__"
23 | ],
24 | "scripts": {
25 | "test": "jest",
26 | "typescript": "tsc --noEmit",
27 | "lint": "eslint \"**/*.{js,ts,tsx}\"",
28 | "prepare": "bob build",
29 | "release": "release-it",
30 | "example": "yarn --cwd example",
31 | "pods": "cd example && pod-install --quiet",
32 | "bootstrap": "yarn example && yarn && yarn pods"
33 | },
34 | "keywords": [
35 | "react-native",
36 | "elements",
37 | "components",
38 | "material",
39 | "textfield",
40 | "input",
41 | "hashtag",
42 | "tags",
43 | "autocomplete"
44 | ],
45 | "repository": "https://github.com/hoaphantn7604/react-native-element-textinput",
46 | "author": "Hoa Phan (https://github.com/hoaphantn7604)",
47 | "license": "MIT",
48 | "bugs": {
49 | "url": "https://github.com/hoaphantn7604/react-native-element-textinput/issues"
50 | },
51 | "homepage": "https://github.com/hoaphantn7604/react-native-element-textinput#readme",
52 | "publishConfig": {
53 | "registry": "https://registry.npmjs.org/"
54 | },
55 | "dependencies": {
56 | "react-native-virtualized-view": "*"
57 | },
58 | "devDependencies": {
59 | "@commitlint/config-conventional": "^11.0.0",
60 | "@react-native-community/eslint-config": "^2.0.0",
61 | "@release-it/conventional-changelog": "^2.0.0",
62 | "@types/jest": "^26.0.0",
63 | "@types/react": "^16.9.19",
64 | "@types/react-native": "0.67.8",
65 | "commitlint": "^11.0.0",
66 | "eslint": "^7.2.0",
67 | "eslint-config-prettier": "^7.0.0",
68 | "eslint-plugin-prettier": "^3.1.3",
69 | "husky": "^6.0.0",
70 | "jest": "^26.0.1",
71 | "pod-install": "^0.1.0",
72 | "prettier": "^2.0.5",
73 | "react": "16.13.1",
74 | "react-native": "0.63.4",
75 | "react-native-builder-bob": "^0.18.0",
76 | "release-it": "^14.2.2",
77 | "typescript": "^4.1.3"
78 | },
79 | "peerDependencies": {
80 | "react": "*",
81 | "react-native": "*"
82 | },
83 | "jest": {
84 | "preset": "react-native",
85 | "modulePathIgnorePatterns": [
86 | "/example/node_modules",
87 | "/lib/"
88 | ]
89 | },
90 | "commitlint": {
91 | "extends": [
92 | "@commitlint/config-conventional"
93 | ]
94 | },
95 | "release-it": {
96 | "git": {
97 | "commitMessage": "chore: release ${version}",
98 | "tagName": "v${version}"
99 | },
100 | "npm": {
101 | "publish": true
102 | },
103 | "github": {
104 | "release": true
105 | },
106 | "plugins": {
107 | "@release-it/conventional-changelog": {
108 | "preset": "angular"
109 | }
110 | }
111 | },
112 | "eslintConfig": {
113 | "root": true,
114 | "extends": [
115 | "@react-native-community",
116 | "prettier"
117 | ],
118 | "rules": {
119 | "prettier/prettier": [
120 | "error",
121 | {
122 | "quoteProps": "consistent",
123 | "singleQuote": true,
124 | "tabWidth": 2,
125 | "trailingComma": "es5",
126 | "useTabs": false
127 | }
128 | ]
129 | }
130 | },
131 | "eslintIgnore": [
132 | "node_modules/",
133 | "lib/"
134 | ],
135 | "prettier": {
136 | "quoteProps": "consistent",
137 | "singleQuote": true,
138 | "tabWidth": 2,
139 | "trailingComma": "es5",
140 | "useTabs": false
141 | },
142 | "react-native-builder-bob": {
143 | "source": "src",
144 | "output": "lib",
145 | "targets": [
146 | "commonjs",
147 | "module",
148 | [
149 | "typescript",
150 | {
151 | "project": "tsconfig.build.json"
152 | }
153 | ]
154 | ]
155 | }
156 | }
157 |
--------------------------------------------------------------------------------
/scripts/bootstrap.js:
--------------------------------------------------------------------------------
1 | const os = require('os');
2 | const path = require('path');
3 | const child_process = require('child_process');
4 |
5 | const root = path.resolve(__dirname, '..');
6 | const args = process.argv.slice(2);
7 | const options = {
8 | cwd: process.cwd(),
9 | env: process.env,
10 | stdio: 'inherit',
11 | encoding: 'utf-8',
12 | };
13 |
14 | if (os.type() === 'Windows_NT') {
15 | options.shell = true
16 | }
17 |
18 | let result;
19 |
20 | if (process.cwd() !== root || args.length) {
21 | // We're not in the root of the project, or additional arguments were passed
22 | // In this case, forward the command to `yarn`
23 | result = child_process.spawnSync('yarn', args, options);
24 | } else {
25 | // If `yarn` is run without arguments, perform bootstrap
26 | result = child_process.spawnSync('yarn', ['bootstrap'], options);
27 | }
28 |
29 | process.exitCode = result.status;
30 |
--------------------------------------------------------------------------------
/src/AutoComplete/icon/close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hoaphantn7604/react-native-element-textinput/ac4d4da289861da7220c138a0560f7a9a71afbcb/src/AutoComplete/icon/close.png
--------------------------------------------------------------------------------
/src/AutoComplete/index.tsx:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-shadow */
2 | import React, { useEffect, useMemo, useState } from 'react';
3 | import {
4 | FlatList,
5 | Image,
6 | Text,
7 | TextInput,
8 | TouchableOpacity,
9 | View,
10 | Keyboard,
11 | StyleProp,
12 | TextStyle,
13 | } from 'react-native';
14 | import { styles } from './styles';
15 | import type { AutoCompleteProps } from './model';
16 | import { ScrollView } from 'react-native-virtualized-view';
17 |
18 | const ic_close = require('./icon/close.png');
19 |
20 | const defaultProps = {
21 | style: {},
22 | value: '',
23 | showIcon: true,
24 | };
25 |
26 | const AutoCompleteComponent: AutoCompleteProps = (props) => {
27 | const {
28 | fontFamily,
29 | style,
30 | inputStyle,
31 | iconStyle,
32 | labelStyle = {},
33 | placeholderStyle = {},
34 | textErrorStyle,
35 | label,
36 | placeholderTextColor = '#000',
37 | placeholder = '',
38 | showIcon,
39 | textError,
40 | focusColor,
41 | data,
42 | value,
43 | onFocus,
44 | onBlur,
45 | onChangeText = (_value: string) => {},
46 | renderLeftIcon,
47 | renderRightIcon,
48 | renderItem,
49 | } = props;
50 |
51 | const [text, setText] = useState('');
52 | const [values, setValues] = useState(null);
53 | const [isFocus, setIsFocus] = useState(false);
54 |
55 | useEffect(() => {
56 | if (value) {
57 | setText(value);
58 | } else {
59 | setText('');
60 | }
61 | }, [value]);
62 |
63 | const onChange = (text: string) => {
64 | setText(text);
65 | onChangeText(text);
66 | onSearch(text);
67 | };
68 |
69 | const onSearch = (text: string) => {
70 | if (text.length > 0 && data) {
71 | const dataSearch = data.filter((e) => {
72 | const item = e
73 | ?.toLowerCase()
74 | .replace(' ', '')
75 | .normalize('NFD')
76 | .replace(/[\u0300-\u036f]/g, '');
77 | const key = text
78 | .toLowerCase()
79 | .replace(' ', '')
80 | .normalize('NFD')
81 | .replace(/[\u0300-\u036f]/g, '');
82 |
83 | return item.indexOf(key) >= 0;
84 | });
85 | setValues(dataSearch);
86 | } else {
87 | setValues([]);
88 | }
89 | };
90 |
91 | const _renderRightIcon = () => {
92 | if (showIcon) {
93 | if (renderRightIcon) {
94 | return renderRightIcon();
95 | }
96 | if (text.length > 0) {
97 | return (
98 | onChange('')}>
99 |
100 |
101 | );
102 | } else {
103 | return null;
104 | }
105 | }
106 | return null;
107 | };
108 |
109 | const font = () => {
110 | if (fontFamily) {
111 | return {
112 | fontFamily: fontFamily,
113 | };
114 | } else {
115 | return {};
116 | }
117 | };
118 |
119 | const onFocusCustom = (e: any) => {
120 | setIsFocus(true);
121 | if (onFocus) {
122 | onFocus(e);
123 | }
124 | };
125 |
126 | const onBlurCustom = (e: any) => {
127 | setIsFocus(false);
128 | if (onBlur) {
129 | onBlur(e);
130 | }
131 | };
132 |
133 | const onSubmitEdit = () => {
134 | if (text.length > 0) {
135 | onChange(text);
136 | }
137 | };
138 |
139 | const _renderItem = ({ item, index }: { item: any; index: number }) => {
140 | return (
141 | {
144 | onChange(item);
145 | setValues(null);
146 | Keyboard.dismiss();
147 | }}
148 | >
149 | {renderItem ? (
150 | renderItem(item)
151 | ) : (
152 |
153 | {item}
154 |
155 | )}
156 |
157 | );
158 | };
159 |
160 | const _renderItemSelected = () => {
161 | if (values && values.length > 0) {
162 | return (
163 |
164 |
165 | index.toString()}
170 | />
171 |
172 |
173 | );
174 | }
175 | return null;
176 | };
177 |
178 | const colorFocus = useMemo(() => {
179 | if (isFocus && focusColor) {
180 | return {
181 | borderBottomColor: focusColor,
182 | borderTopColor: focusColor,
183 | borderLeftColor: focusColor,
184 | borderRightColor: focusColor,
185 | };
186 | } else {
187 | return {};
188 | }
189 | }, [focusColor, isFocus]);
190 |
191 | const styleLable: StyleProp = useMemo(() => {
192 | if (isFocus || (text.length > 0 && label)) {
193 | const style: any = labelStyle;
194 | return {
195 | top: 5,
196 | color: isFocus ? focusColor : null,
197 | ...style,
198 | };
199 | } else {
200 | const style: any = placeholderStyle;
201 | return {
202 | position: 'absolute',
203 | ...style,
204 | };
205 | }
206 | }, [isFocus, text.length, label, focusColor, labelStyle, placeholderStyle]);
207 |
208 | return (
209 | <>
210 |
211 |
212 | {renderLeftIcon?.()}
213 |
214 | {label ? (
215 | {label}
216 | ) : null}
217 |
228 |
229 | {_renderRightIcon()}
230 |
231 |
232 | {_renderItemSelected()}
233 | {textError ? (
234 | {textError}
235 | ) : null}
236 | >
237 | );
238 | };
239 |
240 | AutoCompleteComponent.defaultProps = defaultProps;
241 |
242 | export default AutoCompleteComponent;
243 |
--------------------------------------------------------------------------------
/src/AutoComplete/model.ts:
--------------------------------------------------------------------------------
1 | import type React from 'react';
2 | import type {
3 | ImageStyle,
4 | NativeSyntheticEvent,
5 | StyleProp,
6 | TextInputFocusEventData,
7 | TextInputProps,
8 | TextStyle,
9 | ViewStyle,
10 | } from 'react-native';
11 |
12 | interface IProps extends TextInputProps {
13 | fontFamily?: string;
14 | style?: StyleProp;
15 | inputStyle?: StyleProp;
16 | labelStyle?: StyleProp;
17 | placeholderStyle?: StyleProp;
18 | iconStyle?: StyleProp;
19 | textErrorStyle?: StyleProp;
20 | textError?: string;
21 | label?: string;
22 | showIcon?: boolean;
23 | focusColor?: string;
24 | data?: string[];
25 | onFocus?: (e: NativeSyntheticEvent) => void;
26 | onBlur?: (e: NativeSyntheticEvent) => void;
27 | renderRightIcon?: () => JSX.Element | null | undefined;
28 | renderLeftIcon?: () => JSX.Element | null | undefined;
29 | renderItem?: (item: string) => JSX.Element | null | undefined;
30 | }
31 |
32 | export type AutoCompleteProps = React.FC;
33 |
--------------------------------------------------------------------------------
/src/AutoComplete/styles.ts:
--------------------------------------------------------------------------------
1 | import { StyleSheet } from 'react-native';
2 |
3 | export const styles = StyleSheet.create({
4 | container: {
5 | alignItems: 'center',
6 | height: 60,
7 | },
8 | wrapInput: {
9 | flex: 1,
10 | justifyContent: 'center',
11 | },
12 | textInput: {
13 | flex: 1,
14 | flexDirection: 'row',
15 | alignItems: 'center',
16 | },
17 | input: {
18 | fontSize: 16,
19 | paddingHorizontal: 0,
20 | flex: 1,
21 | color: 'black',
22 | },
23 | label: {
24 | fontSize: 16,
25 | },
26 | row: {
27 | flexDirection: 'row',
28 | },
29 | icon: {
30 | width: 20,
31 | height: 20,
32 | },
33 | textError: {
34 | color: 'red',
35 | fontSize: 14,
36 | marginTop: 10,
37 | },
38 | listContainer: {
39 | marginTop: 2,
40 | borderWidth: 0.5,
41 | borderColor: '#EEEEEE',
42 | backgroundColor: 'white',
43 | shadowColor: '#000',
44 | shadowOffset: {
45 | width: 0,
46 | height: 1,
47 | },
48 | shadowOpacity: 0.2,
49 | shadowRadius: 1.41,
50 | elevation: 2,
51 | },
52 | item: {
53 | paddingHorizontal: 16,
54 | paddingVertical: 8,
55 | flexDirection: 'row',
56 | justifyContent: 'space-between',
57 | alignItems: 'center',
58 | },
59 | textItem: {
60 | flex: 1,
61 | fontSize: 16,
62 | },
63 | });
64 |
--------------------------------------------------------------------------------
/src/HashtagInput/icon/close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hoaphantn7604/react-native-element-textinput/ac4d4da289861da7220c138a0560f7a9a71afbcb/src/HashtagInput/icon/close.png
--------------------------------------------------------------------------------
/src/HashtagInput/index.tsx:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-shadow */
2 | import React, { useCallback, useEffect, useMemo, useState } from 'react';
3 | import {
4 | Image,
5 | StyleProp,
6 | Text,
7 | TextInput,
8 | TextStyle,
9 | TouchableOpacity,
10 | View,
11 | } from 'react-native';
12 | import { styles } from './styles';
13 | import type { HashtagProps } from './model';
14 |
15 | const ic_close = require('./icon/close.png');
16 |
17 | const defaultProps = {
18 | style: {},
19 | value: '',
20 | showIcon: true,
21 | };
22 |
23 | const HashtagInputComponent: HashtagProps = (props) => {
24 | const {
25 | fontFamily,
26 | style,
27 | inputStyle,
28 | iconStyle,
29 | labelStyle,
30 | placeholderStyle = {},
31 | textErrorStyle,
32 | label,
33 | placeholderTextColor = '#000',
34 | placeholder = '',
35 | showIcon,
36 | textError,
37 | focusColor,
38 | data = [],
39 | hashtagStyle,
40 | hashtagTextStyle,
41 | onFocus,
42 | onBlur,
43 | onChangeText = (_value: string) => {},
44 | renderLeftIcon,
45 | renderRightIcon,
46 | onChangeValue = (_value: string[]) => {},
47 | renderHashtagItem,
48 | } = props;
49 |
50 | const [text, setText] = useState('');
51 | const [hashtag, setHashtag] = useState(null);
52 | const [isFocus, setIsFocus] = useState(false);
53 |
54 | const onChange = (text: string) => {
55 | setText(text);
56 | onChangeText(text);
57 | };
58 |
59 | const _renderRightIcon = () => {
60 | if (showIcon) {
61 | if (renderRightIcon) {
62 | return renderRightIcon();
63 | }
64 | if (text.length > 0) {
65 | return (
66 | onChange('')}>
67 |
68 |
69 | );
70 | } else {
71 | return null;
72 | }
73 | }
74 | return null;
75 | };
76 |
77 | const font = useCallback(() => {
78 | if (fontFamily) {
79 | return {
80 | fontFamily: fontFamily,
81 | };
82 | } else {
83 | return {};
84 | }
85 | }, [fontFamily]);
86 |
87 | const onFocusCustom = (e: any) => {
88 | setIsFocus(true);
89 | if (onFocus) {
90 | onFocus(e);
91 | }
92 | };
93 |
94 | const onBlurCustom = (e: any) => {
95 | setIsFocus(false);
96 | if (onBlur) {
97 | onBlur(e);
98 | }
99 | };
100 |
101 | const onRemoveItem = useCallback(
102 | (index: number) => {
103 | if (hashtag) {
104 | if (props.editable === undefined || props.editable) {
105 | var array = [...hashtag];
106 | array.splice(index, 1);
107 | setHashtag(array);
108 | onChangeValue(array);
109 | }
110 | }
111 | },
112 | [hashtag, onChangeValue, props.editable]
113 | );
114 |
115 | useEffect(() => {
116 | if (data) {
117 | setHashtag(data);
118 | } else {
119 | setHashtag(null);
120 | }
121 | }, [data]);
122 |
123 | const onSubmitEdit = () => {
124 | if (hashtag && text.length > 0) {
125 | hashtag.push(text);
126 | setText('');
127 | onChangeValue(hashtag);
128 | }
129 | };
130 |
131 | const _renderItemSelected = useCallback(() => {
132 | if (hashtag && hashtag.length > 0) {
133 | return (
134 |
135 | {hashtag.map((e, index) => {
136 | if (renderHashtagItem) {
137 | return (
138 |
139 | {renderHashtagItem(e, () => {
140 | onRemoveItem(index);
141 | })}
142 |
143 | );
144 | }
145 | return (
146 | {
150 | onRemoveItem(index);
151 | }}
152 | >
153 |
156 | {e}
157 |
158 |
161 | ⓧ
162 |
163 |
164 | );
165 | })}
166 |
167 | );
168 | }
169 | return null;
170 | }, [
171 | font,
172 | hashtag,
173 | hashtagStyle,
174 | hashtagTextStyle,
175 | onRemoveItem,
176 | renderHashtagItem,
177 | ]);
178 |
179 | const colorFocus = useMemo(() => {
180 | if (isFocus && focusColor) {
181 | return {
182 | borderBottomColor: focusColor,
183 | borderTopColor: focusColor,
184 | borderLeftColor: focusColor,
185 | borderRightColor: focusColor,
186 | };
187 | } else {
188 | return {};
189 | }
190 | }, [focusColor, isFocus]);
191 |
192 | const styleLable: StyleProp = useMemo(() => {
193 | if (isFocus || (text.length > 0 && label)) {
194 | const style: any = labelStyle;
195 | return {
196 | top: 5,
197 | color: isFocus ? focusColor : null,
198 | ...style,
199 | };
200 | } else {
201 | const style: any = placeholderStyle;
202 | return {
203 | position: 'absolute',
204 | ...style,
205 | };
206 | }
207 | }, [isFocus, text.length, label, focusColor, labelStyle, placeholderStyle]);
208 |
209 | return (
210 | <>
211 |
212 |
213 | {renderLeftIcon?.()}
214 |
215 | {label ? (
216 | {label}
217 | ) : null}
218 |
229 |
230 | {_renderRightIcon()}
231 |
232 |
233 | {_renderItemSelected()}
234 | {textError ? (
235 | {textError}
236 | ) : null}
237 | >
238 | );
239 | };
240 |
241 | HashtagInputComponent.defaultProps = defaultProps;
242 |
243 | export default HashtagInputComponent;
244 |
--------------------------------------------------------------------------------
/src/HashtagInput/model.ts:
--------------------------------------------------------------------------------
1 | import type React from 'react';
2 | import type {
3 | ImageStyle,
4 | NativeSyntheticEvent,
5 | StyleProp,
6 | TextInputFocusEventData,
7 | TextInputProps,
8 | TextStyle,
9 | ViewStyle,
10 | } from 'react-native';
11 |
12 | interface IProps extends TextInputProps {
13 | fontFamily?: string;
14 | style?: StyleProp;
15 | inputStyle?: StyleProp;
16 | labelStyle?: StyleProp;
17 | placeholderStyle?: StyleProp;
18 | iconStyle?: StyleProp;
19 | textErrorStyle?: StyleProp;
20 | hashtagStyle?: StyleProp;
21 | hashtagTextStyle?: StyleProp;
22 | textError?: string;
23 | label?: string;
24 | showIcon?: boolean;
25 | focusColor?: string;
26 | data?: string[];
27 | onFocus?: (e: NativeSyntheticEvent) => void;
28 | onBlur?: (e: NativeSyntheticEvent) => void;
29 | renderRightIcon?: () => JSX.Element | null | undefined;
30 | renderLeftIcon?: () => JSX.Element | null | undefined;
31 | onChangeValue?: (value: string[]) => void;
32 | renderHashtagItem?: (
33 | item: any,
34 | onRemove?: () => void
35 | ) => JSX.Element | null | undefined;
36 | }
37 |
38 | export type HashtagProps = React.FC;
39 |
--------------------------------------------------------------------------------
/src/HashtagInput/styles.ts:
--------------------------------------------------------------------------------
1 | import { StyleSheet } from 'react-native';
2 |
3 | export const styles = StyleSheet.create({
4 | container: {
5 | alignItems: 'center',
6 | height: 60,
7 | },
8 | wrapInput: {
9 | flex: 1,
10 | justifyContent: 'center',
11 | },
12 | textInput: {
13 | flex: 1,
14 | flexDirection: 'row',
15 | alignItems: 'center',
16 | },
17 | input: {
18 | fontSize: 16,
19 | paddingHorizontal: 0,
20 | flex: 1,
21 | color: 'black',
22 | },
23 | label: {
24 | fontSize: 16,
25 | },
26 | row: {
27 | flexDirection: 'row',
28 | },
29 | icon: {
30 | width: 20,
31 | height: 20,
32 | },
33 | textError: {
34 | color: 'red',
35 | fontSize: 14,
36 | marginTop: 10,
37 | },
38 | wrapSelectItem: {
39 | flexDirection: 'row',
40 | flexWrap: 'wrap',
41 | },
42 | selectedItem: {
43 | alignItems: 'center',
44 | justifyContent: 'center',
45 | paddingHorizontal: 8,
46 | marginTop: 12,
47 | marginRight: 8,
48 | flexDirection: 'row',
49 | },
50 | selectedTextItem: {
51 | marginLeft: 5,
52 | color: 'gray',
53 | fontSize: 16,
54 | },
55 | });
56 |
--------------------------------------------------------------------------------
/src/TagsInput/index.tsx:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-shadow */
2 | import React, { useCallback, useEffect, useMemo, useState } from 'react';
3 | import {
4 | StyleProp,
5 | Text,
6 | TextInput,
7 | TextStyle,
8 | TouchableOpacity,
9 | View,
10 | } from 'react-native';
11 | import { styles } from './styles';
12 | import type { TagsInputProps } from './model';
13 |
14 | const defaultProps = {
15 | style: {},
16 | value: '',
17 | };
18 |
19 | const TagInputComponent: TagsInputProps = (props) => {
20 | const {
21 | fontFamily,
22 | style,
23 | inputStyle,
24 | labelStyle,
25 | placeholderStyle = {},
26 | textErrorStyle,
27 | label,
28 | placeholderTextColor = '#000',
29 | placeholder = '',
30 | textError,
31 | focusColor,
32 | data = [],
33 | tagsStyle,
34 | tagsTextStyle,
35 | onFocus,
36 | onBlur,
37 | onChangeText = (_value: string) => {},
38 | onChangeValue = (_value: string[]) => {},
39 | renderTagsItem,
40 | } = props;
41 |
42 | const [text, setText] = useState('');
43 | const [hashtag, setHashtag] = useState(null);
44 | const [isFocus, setIsFocus] = useState(false);
45 |
46 | const onChange = (text: string) => {
47 | setText(text);
48 | onChangeText(text);
49 | };
50 |
51 | const font = useCallback(() => {
52 | if (fontFamily) {
53 | return {
54 | fontFamily: fontFamily,
55 | };
56 | } else {
57 | return {};
58 | }
59 | }, [fontFamily]);
60 |
61 | const onFocusCustom = (e: any) => {
62 | setIsFocus(true);
63 | if (onFocus) {
64 | onFocus(e);
65 | }
66 | };
67 |
68 | const onBlurCustom = (e: any) => {
69 | setIsFocus(false);
70 | if (onBlur) {
71 | onBlur(e);
72 | }
73 | };
74 |
75 | const onRemoveItem = useCallback(
76 | (index: number) => {
77 | if (hashtag) {
78 | if (props.editable === undefined || props.editable) {
79 | var array = [...hashtag];
80 | array.splice(index, 1);
81 | setHashtag(array);
82 | onChangeValue(array);
83 | }
84 | }
85 | },
86 | [hashtag, onChangeValue, props.editable]
87 | );
88 |
89 | useEffect(() => {
90 | if (data) {
91 | setHashtag(data);
92 | } else {
93 | setHashtag(null);
94 | }
95 | }, [data]);
96 |
97 | const onSubmitEdit = () => {
98 | if (hashtag && text.length > 0) {
99 | hashtag.push(text);
100 | setText('');
101 | onChangeValue(hashtag);
102 | }
103 | };
104 |
105 | const onBackspace = () => {
106 | if (text.length === 0 && hashtag) {
107 | var array = [...hashtag];
108 | array.pop();
109 | setHashtag(array);
110 | onChangeValue(array);
111 | }
112 | };
113 |
114 | const _renderTags = useCallback(() => {
115 | if (hashtag) {
116 | return hashtag.map((e, index) => {
117 | if (renderTagsItem) {
118 | return (
119 |
120 | {renderTagsItem(e, () => {
121 | onRemoveItem(index);
122 | })}
123 |
124 | );
125 | }
126 | return (
127 | {
131 | onRemoveItem(index);
132 | }}
133 | >
134 |
135 | {e}
136 |
137 |
138 | ⓧ
139 |
140 |
141 | );
142 | });
143 | }
144 | return null;
145 | }, [font, hashtag, onRemoveItem, renderTagsItem, tagsStyle, tagsTextStyle]);
146 |
147 | const _renderItemSelected = () => {
148 | return (
149 |
150 | {_renderTags()}
151 | {
162 | if (nativeEvent.key === 'Backspace') {
163 | onBackspace();
164 | }
165 | }}
166 | />
167 |
168 | );
169 | };
170 |
171 | const colorFocus = useMemo(() => {
172 | if (isFocus && focusColor) {
173 | return {
174 | borderBottomColor: focusColor,
175 | borderTopColor: focusColor,
176 | borderLeftColor: focusColor,
177 | borderRightColor: focusColor,
178 | };
179 | } else {
180 | return {};
181 | }
182 | }, [focusColor, isFocus]);
183 |
184 | const styleLable: StyleProp = useMemo(() => {
185 | if (isFocus || (hashtag && hashtag.length > 0 && label)) {
186 | const style: any = labelStyle;
187 | return {
188 | top: 5,
189 | color: focusColor,
190 | ...style,
191 | };
192 | } else {
193 | const style: any = placeholderStyle;
194 | return {
195 | position: 'absolute',
196 | ...style,
197 | };
198 | }
199 | }, [isFocus, hashtag, label, focusColor, labelStyle, placeholderStyle]);
200 |
201 | return (
202 | <>
203 |
204 |
205 |
206 | {label ? (
207 | {label}
208 | ) : null}
209 | {_renderItemSelected()}
210 |
211 |
212 |
213 | {textError ? (
214 | {textError}
215 | ) : null}
216 | >
217 | );
218 | };
219 |
220 | TagInputComponent.defaultProps = defaultProps;
221 |
222 | export default TagInputComponent;
223 |
--------------------------------------------------------------------------------
/src/TagsInput/model.ts:
--------------------------------------------------------------------------------
1 | import type React from 'react';
2 | import type {
3 | NativeSyntheticEvent,
4 | StyleProp,
5 | TextInputFocusEventData,
6 | TextInputProps,
7 | TextStyle,
8 | ViewStyle,
9 | } from 'react-native';
10 |
11 | interface IProps extends TextInputProps {
12 | fontFamily?: string;
13 | style?: StyleProp;
14 | inputStyle?: StyleProp;
15 | labelStyle?: StyleProp;
16 | placeholderStyle?: StyleProp;
17 | textErrorStyle?: StyleProp;
18 | tagsStyle?: StyleProp;
19 | tagsTextStyle?: StyleProp;
20 | textError?: string;
21 | label?: string;
22 | focusColor?: string;
23 | data?: string[];
24 | onFocus?: (e: NativeSyntheticEvent) => void;
25 | onBlur?: (e: NativeSyntheticEvent) => void;
26 | onChangeValue?: (value: string[]) => void;
27 | renderTagsItem?: (
28 | item: any,
29 | onRemove?: () => void
30 | ) => JSX.Element | null | undefined;
31 | }
32 |
33 | export type TagsInputProps = React.FC;
34 |
--------------------------------------------------------------------------------
/src/TagsInput/styles.ts:
--------------------------------------------------------------------------------
1 | import { StyleSheet } from 'react-native';
2 |
3 | export const styles = StyleSheet.create({
4 | container: {
5 | alignItems: 'center',
6 | },
7 | wrapInput: {
8 | flex: 1,
9 | justifyContent: 'center',
10 | },
11 | textInput: {
12 | flex: 1,
13 | flexDirection: 'row',
14 | alignItems: 'center',
15 | },
16 | input: {
17 | fontSize: 16,
18 | paddingHorizontal: 0,
19 | minWidth: 80,
20 | marginVertical: 8,
21 | color: 'black',
22 | },
23 | label: {
24 | fontSize: 16,
25 | },
26 | row: {
27 | flexDirection: 'row',
28 | },
29 | icon: {
30 | width: 20,
31 | height: 20,
32 | },
33 | textError: {
34 | color: 'red',
35 | fontSize: 14,
36 | marginTop: 10,
37 | },
38 | wrapSelectedItem: {
39 | flexDirection: 'row',
40 | flexWrap: 'wrap',
41 | paddingVertical: 8,
42 | },
43 | selectedItem: {
44 | alignItems: 'center',
45 | justifyContent: 'center',
46 | paddingHorizontal: 12,
47 | marginVertical: 4,
48 | marginRight: 8,
49 | flexDirection: 'row',
50 | },
51 | selectedTextItem: {
52 | marginLeft: 5,
53 | color: 'gray',
54 | fontSize: 16,
55 | },
56 | });
57 |
--------------------------------------------------------------------------------
/src/TextInput/icon/close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hoaphantn7604/react-native-element-textinput/ac4d4da289861da7220c138a0560f7a9a71afbcb/src/TextInput/icon/close.png
--------------------------------------------------------------------------------
/src/TextInput/icon/eye.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hoaphantn7604/react-native-element-textinput/ac4d4da289861da7220c138a0560f7a9a71afbcb/src/TextInput/icon/eye.png
--------------------------------------------------------------------------------
/src/TextInput/icon/uneye.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hoaphantn7604/react-native-element-textinput/ac4d4da289861da7220c138a0560f7a9a71afbcb/src/TextInput/icon/uneye.png
--------------------------------------------------------------------------------
/src/TextInput/index.tsx:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-shadow */
2 | import React, { useEffect, useMemo, useState } from 'react';
3 | import {
4 | Image,
5 | StyleProp,
6 | Text,
7 | TextInput,
8 | TextStyle,
9 | TouchableOpacity,
10 | View,
11 | } from 'react-native';
12 | import { styles } from './styles';
13 | import type { InputProps } from './model';
14 |
15 | const ic_eye = require('./icon/eye.png');
16 | const ic_uneye = require('./icon/uneye.png');
17 | const ic_close = require('./icon/close.png');
18 |
19 | const defaultProps = {
20 | style: {},
21 | value: '',
22 | showIcon: true,
23 | currency: false,
24 | numeric: false,
25 | };
26 |
27 | const TextInputComponent: InputProps = (props) => {
28 | const {
29 | fontFamily,
30 | style,
31 | inputStyle,
32 | iconStyle,
33 | labelStyle,
34 | placeholderStyle = {},
35 | textErrorStyle,
36 | value,
37 | label,
38 | placeholderTextColor = '#000',
39 | placeholder = '',
40 | showIcon,
41 | mode = 'default',
42 | textError,
43 | focusColor,
44 | onFocus,
45 | onBlur,
46 | onChangeText = (_value: string) => {},
47 | renderLeftIcon,
48 | renderRightIcon,
49 | } = props;
50 |
51 | const [text, setText] = useState('');
52 | const [isFocus, setIsFocus] = useState(false);
53 | const [textEntry, setTextEntry] = useState(
54 | mode === 'password' ? true : false
55 | );
56 |
57 | useEffect(() => {
58 | if (value) {
59 | if (mode === 'numeric') {
60 | setText(formatNumeric(value));
61 | } else {
62 | setText(value);
63 | }
64 | } else {
65 | setText('');
66 | }
67 | }, [mode, value]);
68 |
69 | const formatNumeric = (num: string) => {
70 | const values = num.toString().replace(/\D/g, '');
71 | return values.toString().replace(/\B(?=(\d{3})+(?!\d))/g, '.');
72 | };
73 |
74 | const reConvertNumeric = (x: string) => {
75 | let s;
76 | s = x.split('.');
77 | s = s.join('');
78 | return s;
79 | };
80 |
81 | const onChange = (text: string) => {
82 | if (mode === 'numeric') {
83 | setText(formatNumeric(text));
84 | onChangeText(reConvertNumeric(text));
85 | } else {
86 | setText(text);
87 | onChangeText(text);
88 | }
89 | };
90 |
91 | const onChangeTextEntry = () => {
92 | setTextEntry(!textEntry);
93 | };
94 |
95 | const _renderRightIcon = () => {
96 | if (showIcon) {
97 | if (renderRightIcon) {
98 | return renderRightIcon();
99 | }
100 | if (text.length > 0) {
101 | if (mode === 'password') {
102 | return (
103 |
104 |
108 |
109 | );
110 | } else {
111 | return (
112 | onChange('')}>
113 |
114 |
115 | );
116 | }
117 | } else {
118 | return null;
119 | }
120 | }
121 | return null;
122 | };
123 |
124 | const font = () => {
125 | if (fontFamily) {
126 | return {
127 | fontFamily: fontFamily,
128 | };
129 | } else {
130 | return {};
131 | }
132 | };
133 |
134 | const onFocusCustom = (e: any) => {
135 | setIsFocus(true);
136 | if (onFocus) {
137 | onFocus(e);
138 | }
139 | };
140 |
141 | const onBlurCustom = (e: any) => {
142 | setIsFocus(false);
143 | if (onBlur) {
144 | onBlur(e);
145 | }
146 | };
147 |
148 | const colorFocus = useMemo(() => {
149 | if (isFocus && focusColor) {
150 | return {
151 | borderBottomColor: focusColor,
152 | borderTopColor: focusColor,
153 | borderLeftColor: focusColor,
154 | borderRightColor: focusColor,
155 | };
156 | } else {
157 | return {};
158 | }
159 | }, [focusColor, isFocus]);
160 |
161 | const styleLable: StyleProp = useMemo(() => {
162 | if (isFocus || (text.length > 0 && label)) {
163 | const style: any = labelStyle;
164 | return {
165 | top: 5,
166 | color: isFocus ? focusColor : null,
167 | ...style,
168 | };
169 | } else {
170 | const style: any = placeholderStyle;
171 | return {
172 | position: 'absolute',
173 | ...style,
174 | };
175 | }
176 | }, [isFocus, text.length, label, focusColor, labelStyle, placeholderStyle]);
177 |
178 | return (
179 | <>
180 |
181 |
182 | {renderLeftIcon?.()}
183 |
184 | {label ? (
185 | {label}
186 | ) : null}
187 |
198 |
199 | {_renderRightIcon()}
200 |
201 |
202 | {textError ? (
203 | {textError}
204 | ) : null}
205 | >
206 | );
207 | };
208 |
209 | TextInputComponent.defaultProps = defaultProps;
210 |
211 | export default TextInputComponent;
212 |
--------------------------------------------------------------------------------
/src/TextInput/model.ts:
--------------------------------------------------------------------------------
1 | import type React from 'react';
2 | import type {
3 | ImageStyle,
4 | NativeSyntheticEvent,
5 | StyleProp,
6 | TextInputFocusEventData,
7 | TextInputProps,
8 | TextStyle,
9 | ViewStyle,
10 | } from 'react-native';
11 |
12 | interface Props extends TextInputProps {
13 | mode?: 'default' | 'numeric' | 'password'
14 | fontFamily?: string;
15 | style?: StyleProp;
16 | inputStyle?: StyleProp;
17 | labelStyle?: StyleProp;
18 | placeholderStyle?: StyleProp;
19 | iconStyle?: StyleProp;
20 | textErrorStyle?: StyleProp;
21 | textError?: string;
22 | label?: string;
23 | showIcon?: boolean;
24 | focusColor?: string;
25 | onFocus?: (e: NativeSyntheticEvent) => void;
26 | onBlur?: (e: NativeSyntheticEvent) => void;
27 | renderRightIcon?: () => JSX.Element | null | undefined;
28 | renderLeftIcon?: () => JSX.Element | null | undefined;
29 | }
30 |
31 | export type InputProps = React.FC;
32 |
--------------------------------------------------------------------------------
/src/TextInput/styles.ts:
--------------------------------------------------------------------------------
1 | import { StyleSheet } from 'react-native';
2 |
3 | export const styles = StyleSheet.create({
4 | container: {
5 | alignItems: 'center',
6 | height: 60,
7 | },
8 | wrapInput: {
9 | flex: 1,
10 | justifyContent: 'center',
11 | },
12 | textInput: {
13 | flex: 1,
14 | flexDirection: 'row',
15 | alignItems: 'center',
16 | },
17 | input: {
18 | fontSize: 16,
19 | paddingHorizontal: 0,
20 | flex: 1,
21 | color: 'black',
22 | },
23 | label: {
24 | fontSize: 16,
25 | },
26 | row: {
27 | flexDirection: 'row',
28 | },
29 | icon: {
30 | width: 20,
31 | height: 20,
32 | },
33 | textError: {
34 | color: 'red',
35 | fontSize: 14,
36 | marginTop: 10,
37 | },
38 | selectedItem: {
39 | height: 30,
40 | alignItems: 'center',
41 | justifyContent: 'center',
42 | borderWidth: 0.5,
43 | borderColor: 'gray',
44 | paddingHorizontal: 8,
45 | marginTop: 12,
46 | marginRight: 8,
47 | flexDirection: 'row',
48 | },
49 | selectedTextItem: {
50 | marginLeft: 5,
51 | color: 'gray',
52 | fontSize: 16,
53 | },
54 | });
55 |
--------------------------------------------------------------------------------
/src/index.tsx:
--------------------------------------------------------------------------------
1 | import TextInput from './TextInput';
2 | import HashtagInput from './HashtagInput';
3 | import TagsInput from './TagsInput';
4 | import AutoComplete from './AutoComplete';
5 |
6 | export { TextInput, HashtagInput, TagsInput, AutoComplete };
7 |
--------------------------------------------------------------------------------
/tsconfig.build.json:
--------------------------------------------------------------------------------
1 |
2 | {
3 | "extends": "./tsconfig",
4 | "exclude": ["example"]
5 | }
6 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "baseUrl": "./",
4 | "paths": {
5 | "react-native-element-textinput": ["./src/index"]
6 | },
7 | "allowUnreachableCode": false,
8 | "allowUnusedLabels": false,
9 | "esModuleInterop": true,
10 | "importsNotUsedAsValues": "error",
11 | "forceConsistentCasingInFileNames": true,
12 | "jsx": "react",
13 | "lib": ["esnext"],
14 | "module": "esnext",
15 | "moduleResolution": "node",
16 | "noFallthroughCasesInSwitch": true,
17 | "noImplicitReturns": true,
18 | "noImplicitUseStrict": false,
19 | "noStrictGenericChecks": false,
20 | "noUnusedLocals": true,
21 | "noUnusedParameters": true,
22 | "resolveJsonModule": true,
23 | "skipLibCheck": true,
24 | "strict": true,
25 | "target": "esnext"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------