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
This commit is contained in:
Geoffrey Goh 2016-08-19 13:54:57 -07:00 committed by Facebook Github Bot 8
parent 8eecb0c2e6
commit f31b6ba953
2 changed files with 20 additions and 2 deletions

View File

@ -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', () => {

View File

@ -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;
}
);