From b5e2e1d52d6fc7550bb19a5e348923b40941be46 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Mon, 12 Apr 2021 00:03:16 -0700 Subject: [PATCH] Expose setSurfaceProps API in JS Summary: This diff introduces the new function "setSurfaceProps" in SurfaceRegistry and AppRegistry This new method will be used to update initialProps of a surface at the root level. In the near future this will be useful to integrate the OffScreen API component in pre-rendering changelog: [internal] internal Reviewed By: JoshuaGross Differential Revision: D27607587 fbshipit-source-id: 3cc58c51924feb68f6a24bf762986c57f9a245ae --- Libraries/ReactNative/AppRegistry.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Libraries/ReactNative/AppRegistry.js b/Libraries/ReactNative/AppRegistry.js index 894d6a291a9..2b37b9a4f73 100644 --- a/Libraries/ReactNative/AppRegistry.js +++ b/Libraries/ReactNative/AppRegistry.js @@ -201,6 +201,33 @@ const AppRegistry = { runnables[appKey].run(appParameters); }, + /** + * Update initial props for a surface that's already rendered + */ + setSurfaceProps(appKey: string, appParameters: any): void { + if (appKey !== 'LogBox') { + const msg = + 'Updating props for Surface "' + + appKey + + '" with ' + + JSON.stringify(appParameters); + infoLog(msg); + BugReporting.addSource( + 'AppRegistry.setSurfaceProps' + runCount++, + () => msg, + ); + } + invariant( + runnables[appKey] && runnables[appKey].run, + `"${appKey}" has not been registered. This can happen if:\n` + + '* Metro (the local dev server) is run from the wrong folder. ' + + 'Check if Metro is running, stop it and restart it in the current project.\n' + + "* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.", + ); + + runnables[appKey].run(appParameters); + }, + /** * Stops an application when a view should be destroyed. *