From c732ca4a954fc43b489feccea4d5c8fc3d3b0933 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Fri, 19 Aug 2016 13:54:57 -0700 Subject: [PATCH] Fix params patch Summary: `this` is a `ReactNativeHost` post RN 0.29, so the current patch doesn't compile. Simply `getResources()` will work for all versions - Post RN 0.29, it will be the method in the outer `MainApplication`, Pre RN 0.29, it will be the method on the `MainActivity`. grabbou Kureev Closes https://github.com/facebook/react-native/pull/9381 Differential Revision: D3744162 fbshipit-source-id: 1fa270bb3268b7b40c6160da948d99ff993c83b1 --- .../rnpm/link/__tests__/android/applyPatch.spec.js | 11 ++++++++++- .../rnpm/link/src/android/patches/applyParams.js | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/local-cli/rnpm/link/__tests__/android/applyPatch.spec.js b/local-cli/rnpm/link/__tests__/android/applyPatch.spec.js index 43af95b7c2b..0994b24aea4 100644 --- a/local-cli/rnpm/link/__tests__/android/applyPatch.spec.js +++ b/local-cli/rnpm/link/__tests__/android/applyPatch.spec.js @@ -1,3 +1,12 @@ +/** + * Copyright (c) 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + 'use strict'; jest.autoMockOff(); @@ -8,7 +17,7 @@ describe('applyParams', () => { it('apply params to the string', () => { expect( applyParams('${foo}', {foo: 'foo'}, 'react-native') - ).toEqual('this.getResources().getString(R.string.reactNative_foo)'); + ).toEqual('getResources().getString(R.string.reactNative_foo)'); }); it('use null if no params provided', () => { diff --git a/local-cli/rnpm/link/src/android/patches/applyParams.js b/local-cli/rnpm/link/src/android/patches/applyParams.js index 44f4d162479..21c1e9545bc 100644 --- a/local-cli/rnpm/link/src/android/patches/applyParams.js +++ b/local-cli/rnpm/link/src/android/patches/applyParams.js @@ -1,3 +1,12 @@ +/** + * Copyright (c) 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + const toCamelCase = require('lodash').camelCase; module.exports = function applyParams(str, params, prefix) { @@ -7,7 +16,7 @@ module.exports = function applyParams(str, params, prefix) { const name = toCamelCase(prefix) + '_' + param; return params[param] - ? `this.getResources().getString(R.string.${name})` + ? `getResources().getString(R.string.${name})` : null; } );