Skip to content

Commit 6cf9658

Browse files
author
Kureev Alexey
committed
Using prefixes based on react-native module name
1 parent c7b37c0 commit 6cf9658

File tree

7 files changed

+26
-13
lines changed

7 files changed

+26
-13
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"npmlog": "^2.0.0",
3838
"plist": "^1.2.0",
3939
"semver": "^5.1.0",
40+
"to-camel-case": "^1.0.0",
4041
"xcode": "^0.8.2"
4142
},
4243
"devDependencies": {

src/android/patches/0.17/makePackagePatch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const applyParams = require('../applyParams');
22

3-
module.exports = function makePackagePatch(packageInstance, params) {
4-
const processedInstance = applyParams(packageInstance, params);
3+
module.exports = function makePackagePatch(packageInstance, params, prefix) {
4+
const processedInstance = applyParams(packageInstance, params, prefix);
55

66
return {
77
pattern: '.addPackage(new MainReactPackage())',

src/android/patches/0.18/makePackagePatch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const applyParams = require('../applyParams');
22

3-
module.exports = function makePackagePatch(packageInstance, params) {
4-
const processedInstance = applyParams(packageInstance, params);
3+
module.exports = function makePackagePatch(packageInstance, params, prefix) {
4+
const processedInstance = applyParams(packageInstance, params, prefix);
55

66
return {
77
pattern: 'new MainReactPackage()',

src/android/patches/0.20/makePackagePatch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const applyParams = require('../applyParams');
22

3-
module.exports = function makePackagePatch(packageInstance, params) {
4-
const processedInstance = applyParams(packageInstance, params);
3+
module.exports = function makePackagePatch(packageInstance, params, prefix) {
4+
const processedInstance = applyParams(packageInstance, params, prefix);
55

66
return {
77
pattern: 'new MainReactPackage()',

src/android/patches/applyParams.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
module.exports = function applyParams(str, params) {
1+
const toCamelCase = require('to-camel-case');
2+
3+
module.exports = function applyParams(str, params, prefix) {
24
return str.replace(
35
/\$\{(\w+)\}/g,
4-
(pattern, paramName) => params[paramName]
5-
? `this.getResources().getString(R.strings.${paramName})`
6-
: null
6+
(pattern, paramName) => {
7+
const formattedName = toCamelCase(`${prefix}-${paramName}`);
8+
9+
return params[paramName]
10+
? `this.getResources().getString(R.strings.${formattedName})`
11+
: null;
12+
}
713
);
814
};

src/android/registerNativeModule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = function registerNativeAndroidModule(
3434

3535
applyPatch(
3636
projectConfig.mainActivityPath,
37-
makePackagePatch(androidConfig.packageInstance, params)
37+
makePackagePatch(androidConfig.packageInstance, params, name)
3838
);
3939

4040
applyPatch(

test/android/patches/applyPatch.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ const applyParams = require('../../../src/android/patches/applyParams');
55
describe('applyParams', () => {
66
it('apply params to the string', () => {
77
expect(
8-
applyParams('${foo}', {foo: 'foo'})
9-
).to.be.equal('this.getResources().getString(R.strings.foo)');
8+
applyParams('${foo}', {foo: 'foo'}, 'react-native')
9+
).to.be.equal('this.getResources().getString(R.strings.reactNativeFoo)');
10+
});
11+
12+
it('use null if no params provided', () => {
13+
expect(
14+
applyParams('${foo}', {}, 'react-native')
15+
).to.be.equal('null');
1016
});
1117
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy