From 4fd0442482b4e96d7a26e09bb63b6515f923699b Mon Sep 17 00:00:00 2001 From: Lawrence Cheuk Date: Thu, 16 Aug 2018 18:23:04 +0800 Subject: [PATCH] fix: fixed android flash crash when subtitle =' ' (empty string) (#469) reference: https://github.com/wix/react-native-navigation/issues/2892 in short, javascript A && B syntax will return A if A is false. if A is empty string, it will return empty string (which is false if evaluated as boolean) this most of the time works but not here. {A && `sth`}, will return "" when A is empty string. This have no problem in iPhone, but returning an empty string to rn component other that` `will crash in android. The fatal error message can only be viewed using android device monitor or logcat, no message will show in console (as it is a flash crash). To reproduce, put an empty string in subtitle. the double !! first turn empty string '' to true and then false. return false or null is save within JSX 07-26 21:07:41.735: E/AndroidRuntime(16154): java.lang.RuntimeException: abi26_0_0.com.facebook.react.uimanager.IllegalViewOperationException: Trying to add unknown view tag: 1472 07-26 21:07:41.735: E/AndroidRuntime(16154): detail: View tag:1479 07-26 21:07:41.735: E/AndroidRuntime(16154): children(2): [ 07-26 21:07:41.735: E/AndroidRuntime(16154): 1468,1470, 07-26 21:07:41.735: E/AndroidRuntime(16154): ], 07-26 21:07:41.735: E/AndroidRuntime(16154): viewsToAdd(1): [ 07-26 21:07:41.735: E/AndroidRuntime(16154): [2,1472], 07-26 21:07:41.735: E/AndroidRuntime(16154): ], 07-26 21:07:41.735: E/AndroidRuntime(16154): at abi26_0_0.com.facebook.react.bridge.ReactContext.handleException(ReactContext.java:313) 07-26 21:07:41.735: E/AndroidRuntime(16154): at abi26_0_0.com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:33) ### Motivation ### Test plan --- src/components/Appbar/AppbarContent.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Appbar/AppbarContent.js b/src/components/Appbar/AppbarContent.js index 397eaea..bb930ff 100644 --- a/src/components/Appbar/AppbarContent.js +++ b/src/components/Appbar/AppbarContent.js @@ -79,14 +79,14 @@ class AppbarContent extends React.Component { > {title} - {subtitle && ( + {subtitle ? ( {subtitle} - )} + ) : null} ); }