Android App is crashing in Release build react-native 0.55.3 undefined is not an object (evaluating 'p.View.prototype.render')
Closed this issue · 15 comments
Android: custom fonts not applied in debug build, and crashes in the release build
IOS: works fine in both debug and release builds
"react": "16.3.1",
"react-native": "0.55.3",
"react-native-global-props": "^1.1.3",
Here is the log:
07-13 23:12:20.344 23097-23120/? E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
Process: com.-.-, PID: 23097
com.facebook.react.common.JavascriptException: undefined is not an object (evaluating 'p.View.prototype.render'), stack:
setCustomView@458:161
@445:58
d@2:768
n@2:409
t@2:262
@306:191
d@2:768
n@2:409
t@2:262
@12:42
d@2:768
n@2:339
t@2:262
global code@464:8
at com.facebook.react.modules.core.ExceptionsManagerModule.showOrThrowError(ExceptionsManagerModule.java:54)
at com.facebook.react.modules.core.ExceptionsManagerModule.reportFatalException(ExceptionsManagerModule.java:38)
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:160)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:742)
at android.os.Handler.dispatchMessage(Handler.java:95)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
at android.os.Looper.loop(Looper.java:157)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:192)
at java.lang.Thread.run(Thread.java:818)
I also ran into an issue when upgrading react-native. I was using setCustomText, but the issue seems to be that Text.prototype is now undefined.
Take a look at this guys. I'm no longer using this library but this fix worked for me.
Can you please explain how exactly did you apply that fix and make this lib work again in RN 0.56?
As I mention above @dackom, I am no longer using this library. Having said that, the included link demonstrates how to add an empty defaultProps
to Text
and then you can modify any props available on the Text
component.
My example demonstrates how to change allowFontScaling
but you can do this for any property available on the Text
component.
Yeah, but I dont know where should I put that piece of code to change default text properties. :-)
Ideally before you use Text
in your code. Anywhere at the top of your index.js
or App.js
should do the trick.
I putted this:
if (Text.defaultProps==null) Text.defaultProps = {}; Text.defaultProps.fontFamily="Open Sans";
...After imports and before export default class App... in App.js ...
And nothing happens. I also tried just for example color="#F00" ... and also nothing happened.
I tried to do same in index.js, but I needed to also import Text from react-native in order not to get error. But it still didn't work.
Only props can be changed with the proposed solution @dackom. Custom styles are not props. Please do honor the thread by sticking to the topic of the app crashing. The authors of the library are aware that it no longer works and there is no solution to modify fonts as far as I know.
I update setCustomText.js and it works:
import { Text } from 'react-native'
export const setCustomText = customProps => {
const TextRender = Text.render
const initialDefaultProps = Text.defaultProps
Text.defaultProps = {
...initialDefaultProps,
...customProps
}
Text.render = function render(props) {
let oldProps = props
props = { ...props, style: [customProps.style, props.style] }
try {
return TextRender.apply(this, arguments)
} finally {
props = oldProps
}
}
}
Or create your own configuration file like this:
import { Text } from 'react-native'
////////////////// TEXT //////////////////
const customText = { style: { fontSize: 20 } }
setCustomText = customProps => {
const TextRender = Text.render
const initialDefaultProps = Text.defaultProps
Text.defaultProps = {
...initialDefaultProps,
...customProps
}
Text.render = function render(props) {
let oldProps = props
props = { ...props, style: [customProps.style, props.style] }
try {
return TextRender.apply(this, arguments)
} finally {
props = oldProps
}
}
}
//////////////////////////////////////////
////////////// CONFIGURATION //////////////
const loadGlobalProps = () => {
setCustomText(customText)
}
//////////////////////////////////////////
export default loadGlobalProps
@luisfuertes can you create a PR?
In the next 3 weeks I will be too busy, but the second week of October I will have time.
The PR is applying those changes in all setCustom
components
I converted all custom functions thanks to @luisfuertes's code since I needed this today, feel free to use it : https://github.com/maieonbrix/react-native-global-props/
If you want I can submit a PR with better commits but I guess that @luisfuertes already got this so just tell me
Anyway a big thanks to to Andrew for this repo and Luis for this solution :)
@maieonbrix If you have them complete already, it would be very helpful. Thanks! :)