Expo config plugin to make react-native-text-input-mask works on iOS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { withDangerousMod, createRunOncePlugin } = require('@expo/config-plugins'); | |
const { readFile, writeFile } = require('fs'); | |
const pkg = require('../node_modules/react-native-text-input-mask/package.json'); | |
function withIosTextInputMask(config) { | |
return withDangerousMod(config, [ | |
'ios', | |
async (config) => { | |
const filePath = 'ios/Podfile'; | |
const RCTText = | |
" pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text', :modular_headers => true"; | |
readFile(filePath, 'utf8', (err, data) => { | |
if (err) throw err; | |
const transformedData = data.toString().split('\n'); | |
const lineNumber = transformedData.indexOf(' use_react_native!('); | |
if (lineNumber === -1) { | |
// eslint-disable-next-line no-throw-literal | |
throw 'Error adding React-RCTText to Podfile. Reference not found to be able to edit the file.'; | |
} | |
transformedData.splice(lineNumber, 0, RCTText); | |
const modifiedPodfile = transformedData.join('\n'); | |
writeFile(filePath, modifiedPodfile, (err) => { | |
if (err) throw err; | |
console.log('React-RCTText successfully added to Podfile.'); | |
}); | |
}); | |
return config; | |
}, | |
]); | |
} | |
module.exports = createRunOncePlugin(withIosTextInputMask, pkg.name, pkg.version); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment