|
| 1 | +<h1 align="center"> |
| 2 | + <br> |
| 3 | + React-Native-Text-Input-Mask |
| 4 | + <br> |
| 5 | +</h1> |
| 6 | + |
| 7 | +<h3 align="center">Text input mask for React Native on iOS and Android.</h4> |
| 8 | + |
| 9 | +<h4 align="center">Forked from |
| 10 | + <a href="https://github.com/react-native-community/react-native-text-input-mask">react-native-community/react-native-text-input-mask</a> (Ivan Zotov). |
| 11 | +</h4> |
| 12 | + |
| 13 | +<h4 align="center"> |
| 14 | +<a href="https://github.com/drawciamage/react-native-text-input-mask/LICENSE"> |
| 15 | + <img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT license." /> |
| 16 | +</a> |
| 17 | +</h4> |
| 18 | + |
| 19 | +## 📝 Additional Features |
| 20 | + |
| 21 | +- Rewritten with React Hooks. |
| 22 | +- Eslint-config updated to 1.1.0. |
| 23 | +- Fix "componentWillReceiveProps" Warnings. |
| 24 | +- Fix "FATAL EXCEPTION: IndexOutOfBoundsException". |
| 25 | +- Fix "Android Backspace Rendering Issue". |
| 26 | + |
| 27 | +<br> |
| 28 | + ONLY TESTED IN ANDROID 9. |
| 29 | + |
| 30 | +## 💻 Examples |
| 31 | + |
| 32 | +<h4 align="center"> |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +</h4> |
| 38 | + |
| 39 | +## 🏗️ Setup |
| 40 | + |
| 41 | +```bash |
| 42 | +npm install --save drawciamage/react-native-text-input-mask |
| 43 | +# --- or --- |
| 44 | +yarn add https://github.com/drawciamage/react-native-text-input-mask.git |
| 45 | +``` |
| 46 | + |
| 47 | +# 💻 Installation |
| 48 | + |
| 49 | +<details> |
| 50 | + <summary><b>For RN >= 0.61</b></summary> |
| 51 | + |
| 52 | +#### iOS |
| 53 | + |
| 54 | +1. Add following lines to your target in `Podfile` |
| 55 | + |
| 56 | +``` |
| 57 | +use_frameworks! |
| 58 | +pod 'RNInputMask', :path => '../node_modules/react-native-text-input-mask/ios/InputMask' |
| 59 | +``` |
| 60 | + |
| 61 | +2. Run following command |
| 62 | + |
| 63 | +```bash |
| 64 | +cd ios && pod install |
| 65 | +``` |
| 66 | + |
| 67 | +#### Android |
| 68 | + |
| 69 | +No need to do anything. |
| 70 | + |
| 71 | +</details> |
| 72 | + |
| 73 | +<details> |
| 74 | + <summary><b>For RN = 0.60.*</b></summary> |
| 75 | + |
| 76 | +#### iOS |
| 77 | + |
| 78 | +1. In XCode, in the project navigator, right click your `[your project's name]` folder, choose ➜ `Add Files to [your project's name]` |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | +2. Select `Swift File` ➜ `Next` |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | +3. Specify name for example `Dummy.swift` ➜ `Create` |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | +4. Now a pop up is shown select `Create Bridging Header` |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | +5. Add following line to your target in `Podfile` |
| 95 | + |
| 96 | +``` |
| 97 | +pod 'RNInputMask', :path => '../node_modules/react-native-text-input-mask/ios/InputMask' |
| 98 | +``` |
| 99 | + |
| 100 | +6. Run following command |
| 101 | + |
| 102 | +```bash |
| 103 | +cd ios && pod install |
| 104 | +``` |
| 105 | + |
| 106 | +#### Android |
| 107 | + |
| 108 | +No need to do anything. |
| 109 | + |
| 110 | +</details> |
| 111 | + |
| 112 | +<details><summary><b>For RN < 0.60</b></summary> |
| 113 | + |
| 114 | +### Auto Linking |
| 115 | + |
| 116 | +```bash |
| 117 | +react-native link react-native-text-input-mask |
| 118 | +``` |
| 119 | + |
| 120 | +**iOS only:** you have to drag and drop `InputMask.framework` to `Embedded Binaries` in General tab of Target |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | +### Manual installation |
| 125 | + |
| 126 | +#### iOS |
| 127 | + |
| 128 | +1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]` |
| 129 | +2. Go to `node_modules` ➜ `react-native-text-input-mask` and add `RNTextInputMask.xcodeproj` |
| 130 | +3. In XCode, in the project navigator, select your project. Add `libRNTextInputMask.a` to your project's `Build Phases` ➜ `Link Binary With Libraries` |
| 131 | +4. Run your project (`Cmd+R`) |
| 132 | + |
| 133 | +#### Android |
| 134 | + |
| 135 | +1. Open up `android/app/src/main/java/[...]/MainActivity.java` |
| 136 | + |
| 137 | +- Add `import com.RNTextInputMask.RNTextInputMaskPackage;` to the imports at the top of the file |
| 138 | +- Add `new RNTextInputMaskPackage()` to the list returned by the `getPackages()` method |
| 139 | + |
| 140 | +2. Append the following lines to `android/settings.gradle`: |
| 141 | + ``` |
| 142 | + include ':react-native-text-input-mask' |
| 143 | + project(':react-native-text-input-mask').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-text-input-mask/android') |
| 144 | + ``` |
| 145 | +3. Insert the following lines inside the dependencies block in `android/app/build.gradle`: |
| 146 | +`compile project(':react-native-text-input-mask')` |
| 147 | +</details> |
| 148 | + |
| 149 | +## 👨🏫 Usage |
| 150 | + |
| 151 | +```javascript |
| 152 | +import React, { useRef } from "react"; |
| 153 | +import TextInputMask from 'react-native-text-input-mask'; |
| 154 | +... |
| 155 | +const input = useRef(); |
| 156 | +<TextInputMask |
| 157 | + refInput={ref => { input.current = ref }} |
| 158 | + onChangeText={(formatted, extracted) => { |
| 159 | + console.log(formatted) // +1 (123) 456-78-90 |
| 160 | + console.log(extracted) // 1234567890 |
| 161 | + }} |
| 162 | + mask={"+1 ([000]) [000] [00] [00]"} |
| 163 | +/> |
| 164 | +... |
| 165 | +``` |
| 166 | + |
| 167 | +## 📝 More info |
| 168 | + |
| 169 | +[RedMadRobot Input Mask Android](https://github.com/RedMadRobot/input-mask-android) |
| 170 | + |
| 171 | +[RedMadRobot Input Mask IOS](https://github.com/RedMadRobot/input-mask-ios) |
| 172 | + |
| 173 | +## 📆 Versioning |
| 174 | + |
| 175 | +This project uses semantic versioning: MAJOR.MINOR.PATCH. |
| 176 | +This means that releases within the same MAJOR version are always backwards compatible. For more info see [semver.org](http://semver.org/). |
0 commit comments