Workaround to avoid bridge access from ReactTextView for Venice

Summary:
D14014668 introduced support for nesting views within Text on Android. Part of the implementation involved accessing the UIManagerModule from ReactTextView through context. This doesn't work in bridgeless RN because we have no UIManagerModule, and the ReactContext has no Catalyst instance. Trying to access the Catalyst instance from ReactContext throws an exception if it doesn't exist, so i'm just adding a simple check here to make sure the instance exists before proceeding.

This means that this feature won't work in bridgeless mode, but that's ok for now - eventually we want to change the way this works so that it doesn't rely on accessing views in Java, which is potentially unsafe (there's nothing to stop you from mutating the views, and cpp/js would never know about it).

Reviewed By: mdvacca

Differential Revision: D15703100

fbshipit-source-id: 0448d55b8345fc707a25210a505cb6ac520c708a
This commit is contained in:
Emily Janzer 2019-06-10 13:50:58 -07:00 коммит произвёл Facebook Github Bot
Родитель bbeace1342
Коммит 5c399a9f74
1 изменённых файлов: 6 добавлений и 0 удалений

Просмотреть файл

@ -114,6 +114,12 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
return;
}
if (!getReactContext().hasCatalystInstance()) {
// In bridgeless mode there's no Catalyst instance; in that case, bail.
// TODO (T45503888): Figure out how to support nested views from JS or cpp.
return;
}
UIManagerModule uiManager = getReactContext().getNativeModule(UIManagerModule.class);
Spanned text = (Spanned) getText();