Skip to content

Commit

Permalink
support patching iOS, JavaScript and Java react-native files (#11)
Browse files Browse the repository at this point in the history
* patch works ios and js

* use TextImproved native component on Android
  • Loading branch information
fabOnReact authored Jan 20, 2024
1 parent 0d805ea commit 0540e72
Show file tree
Hide file tree
Showing 12 changed files with 460 additions and 71 deletions.
6 changes: 3 additions & 3 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ PODS:
- React-Mapbuffer (0.73.0):
- glog
- React-debug
- react-native-text (0.1.0):
- react-native-text (0.1.8):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
Expand Down Expand Up @@ -1351,7 +1351,7 @@ SPEC CHECKSUMS:
React-jsinspector: 9f6fb9ed9f03a0fb961ab8dc2e0e0ee0dc729e77
React-logger: 008caec0d6a587abc1e71be21bfac5ba1662fe6a
React-Mapbuffer: 58fe558faf52ecde6705376700f848d0293d1cef
react-native-text: 4bc0473066cd30ae02a060e84ca592e93b3c963a
react-native-text: 83ab23e90480b1bc84541067c5f2096c8ebe3559
React-nativeconfig: a063483672b8add47a4875b0281e202908ff6747
React-NativeModulesApple: 169506a5fd708ab22811f76ee06a976595c367a1
React-perflogger: b61e5db8e5167f5e70366e820766c492847c082e
Expand All @@ -1377,4 +1377,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 931a358503c481191c197e8a8eb6267f1e62350e

COCOAPODS: 1.14.2
COCOAPODS: 1.14.3
4 changes: 2 additions & 2 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ export default function App() {
<>
<View style={styles.container}>
<View style={styles.flexBrokenStyle}>
<TextImproved
<Text
textBreakStrategy="simple"
style={styles.parentText}
numberOfLines={1}
>
{email}
</TextImproved>
</Text>
</View>
<TextInput style={styles.input} />
<Text>Normal Text</Text>
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@
"!**/__mocks__",
"!**/.*"
],
"bin": {
"rn-networking-patch": "patch.js"
},
"scripts": {
"example": "yarn workspace react-native-improved-example",
"test": "jest",
"typecheck": "tsc --noEmit",
"lint": "eslint \"**/*.{js,ts,tsx}\"",
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
"prepare": "bob build",
"release": "release-it"
"release": "release-it",
"patch": "node patch.js",
"postinstall": "yarn run patch"
},
"keywords": [
"react-native",
Expand Down
83 changes: 83 additions & 0 deletions patch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env node

// Credits to ifsnow/react-native-networking-patch
// https://github.com/ifsnow/react-native-networking-patch/blob/master/patch.js

const fs = require('fs');
const path = require('path');

const rootPath = path.join(__dirname, '.');

// ============================================================================
// Get RN version
// ============================================================================
// const RNRootPath = path.join(__dirname, '..', 'react-native');
const RNRootPath = path.join(
__dirname,
'./example/node_modules',
'react-native'
);
const RNPackageFile = `${RNRootPath}/package.json`;
if (!fs.existsSync(RNPackageFile)) {
console.log('[!] Not exists react-native');
process.exit(1);
}

const packageFile = fs.readFileSync(RNPackageFile);
let packageJSON = null;

try {
packageJSON = JSON.parse(packageFile);
} catch (e) {
console.error(e);
}

if (!packageJSON) {
console.log('[!] Failed to get version of react-native');
process.exit(1);
}

const patchDir = packageJSON.version;
const isPatchExists =
patchDir !== '' && fs.existsSync(`${rootPath}/patches/${patchDir}`);
if (!isPatchExists) {
const supportVersions = fs
.readdirSync(`${rootPath}/patches`)
.filter((dir) => dir.match(/^\d/))
.join(', ');
console.log(`[!] Unsupported react-native version! (${patchDir})`);
console.log(`[!] Supported react-native versions: ${supportVersions}`);
process.exit(1);
}

function getAllFiles(dirPath, arrayOfFiles) {
const files = fs.readdirSync(dirPath);

arrayOfFiles = arrayOfFiles || [];

files.forEach(function (file) {
if (file === '.DS_Store') {
return;
}

const filePath = `${dirPath}/${file}`;
if (fs.statSync(filePath).isDirectory()) {
arrayOfFiles = getAllFiles(filePath, arrayOfFiles);
} else {
arrayOfFiles.push(filePath);
}
});

return arrayOfFiles;
}

// ============================================================================
// Copy files
// ============================================================================
const targetFilesDir = `${rootPath}/patches/${patchDir}/files`;
getAllFiles(targetFilesDir).forEach(function (sourceFile) {
const destFile = `${RNRootPath}${sourceFile.replace(targetFilesDir, '')}`;
fs.copyFileSync(sourceFile, destFile);
});

console.log('[!] React Native was patched!');
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 0540e72

Please sign in to comment.