Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Expo config plugin to make react-native-text-input-mask works on iOS.
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!(:path => config["reactNativePath"])'
);
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