Skip to content

Commit f76a8c3

Browse files
committed
rn 0.56 compatibility
1 parent 4d5f428 commit f76a8c3

File tree

4 files changed

+60
-6
lines changed

4 files changed

+60
-6
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ React-Native text gradient component for iOS & Android.
2424
- iOS - component works as drop-in replacement for standard `Text` component, e.g. it is possible to have nested gradients;
2525
- Android - currently only basic 'wrapper'-like behavior without nesting is supported, [WIP](https://github.com/iyegoroff/react-native-text-gradient/tree/android-nested-gradient);
2626
- React-Native:
27-
- rn 0.56 is not yet supported;
28-
- with rn >= 0.55.0 use latest version;
27+
- with rn >= 0.56.0 use 0.0.11 and [patch](#Usage with rn 0.56.0);
28+
- with rn >= 0.55.0 use 0.0.9;
2929
- with rn >= 0.54.0 use 0.0.7;
3030
- with rn >= 0.53.1 use 0.0.4;
3131
- rn 0.53.0 is not supported;
@@ -90,6 +90,13 @@ Optional. If true gradient will be calculated for text view background frame rat
9090
<img src="img/useViewFrame.png" width="300">
9191

9292

93+
# Usage with rn 0.56.0
94+
95+
react-native should be patched, because of failing invariant checks
96+
97+
`$ node node_modules/react-native-text-gradient/patch-rn.js`
98+
99+
93100
## Caveats
94101

95102
When mixing several text gradients and `Text`s top component always should be text gradient.

TextGradientExample/package-lock.json

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TextGradientExample/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
"version": "0.0.1",
44
"private": true,
55
"scripts": {
6+
"postinstall": "npm run patch:rn",
7+
"patch:rn": "node node_modules/react-native-text-gradient/patch-rn.js",
68
"reset:packager": "watchman watch-del-all && node_modules/react-native/scripts/packager.sh --reset-cache",
79
"start": "node node_modules/react-native/local-cli/cli.js start",
810
"test": "jest"
911
},
1012
"dependencies": {
1113
"react": "16.4.1",
1214
"react-native": "0.56.0",
13-
"react-native-text-gradient": "0.0.10"
15+
"react-native-text-gradient": "github:iyegoroff/react-native-text-gradient"
1416
},
1517
"devDependencies": {
1618
"babel-jest": "23.2.0",

patch-rn.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs');
4+
const { promisify } = require('util');
5+
const glob = require('glob');
6+
7+
const patterns = [
8+
new RegExp(
9+
'type === "AndroidTextInput" \\\|\\| // Android[\\s\\S]+' +
10+
'type === "RCTMultilineTextInputView" \\|\\| // iOS[\\s\\S]+' +
11+
'type === "RCTSinglelineTextInputView" \\|\\| // iOS[\\s\\S]+' +
12+
'type === "RCTText" \\|\\|[\\s\\S]+' +
13+
'type === "RCTVirtualText"'
14+
),
15+
16+
new RegExp(
17+
'"AndroidTextInput" === props \\|\\|[\\s\\S]+' +
18+
'"RCTMultilineTextInputView" === props \\|\\|[\\s\\S]+' +
19+
'"RCTSinglelineTextInputView" === props \\|\\|[\\s\\S]+' +
20+
'"RCTText" === props \\|\\|[\\s\\S]+' +
21+
'"RCTVirtualText" === props'
22+
)
23+
];
24+
25+
const patches = [
26+
'type.includes("Text")',
27+
28+
'props.includes("Text")'
29+
]
30+
31+
const patchFile = async (file) => {
32+
const content = (await promisify(fs.readFile)(file)).toString();
33+
const patched = content
34+
.replace(patterns[0], patches[0])
35+
.replace(patterns[1], patches[1])
36+
37+
await promisify(fs.writeFile)(file, patched);
38+
};
39+
40+
const patchAll = async () => {
41+
const files = await promisify(glob)('node_modules/react-native/Libraries/Renderer/oss/*');
42+
43+
await Promise.all(files.map(patchFile));
44+
};
45+
46+
patchAll();

0 commit comments

Comments
 (0)