-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support sending messages from shell to Web
One can now pass a `webHandle` ref to shell components and use this handle to send messages to the web side. On the later, one can use `WebjsContext.onShellMessage` to register handlers. During feature creation, one must register a Web handler thanks to `FeatureBuilder.withWebHandler` and provide a `handlerId` to disambiguate between different messages.
- Loading branch information
Showing
20 changed files
with
629 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/acceptance-tests/src/webshell-features.tstest.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React, { createRef } from 'react'; | ||
import makeWebshell, { | ||
FeatureBuilder, | ||
WebHandle | ||
} from '@formidable-webview/webshell'; | ||
import WebView from 'react-native-webview'; | ||
|
||
const Feature1 = new FeatureBuilder({ | ||
defaultOptions: {}, | ||
featureIdentifier: 'test', | ||
script: '' | ||
}) | ||
.withWebHandler<{ foo: string }, 'event1'>('event1') | ||
.withWebHandler<{ bar: string }, 'event2'>('event2') | ||
.build(); | ||
|
||
const feature1 = new Feature1(); | ||
|
||
const Webshell = makeWebshell(WebView, feature1); | ||
|
||
const webHandle = createRef<WebHandle>(); | ||
|
||
webHandle.current?.postMessageToWeb(feature1, 'event1', { | ||
foo: '' | ||
}); | ||
|
||
webHandle.current?.postMessageToWeb(feature1, 'event2', { | ||
bar: '' | ||
}); | ||
|
||
// Should not throw error | ||
<Webshell webHandle={webHandle} />; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.