Skip to content

Commit

Permalink
fix: Fix for SMS Share on React Native WebView
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Apr 11, 2023
1 parent 8b4e188 commit 154b301
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/impl/PromptAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export class PromptAction implements Action {

// eslint-disable-next-line @typescript-eslint/no-unused-vars
execute(_event: AppEvent, _extole: ExtoleInternal) {
// not implemented on react native
}
}
20 changes: 19 additions & 1 deletion src/impl/ViewFullScreenAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import WebView, { WebViewMessageEvent } from 'react-native-webview';
import type { Action } from '../Action';
import type { AppEvent } from './AppEvent';
import type { ExtoleInternal } from './ExtoleInternal';
import { Dimensions, Share } from 'react-native';
import { Dimensions, Linking, Share } from 'react-native';
import React from 'react';


Expand Down Expand Up @@ -33,6 +33,24 @@ export class ViewFullScreenAction implements Action {
height: Dimensions.get('window').height,
}}
injectedJavaScriptBeforeContentLoaded={injectedJavaScriptBeforeContentLoaded}
originWhitelist={['http://*', 'https://*', 'sms:*', 'tel:*', 'mailto:*']}
onShouldStartLoadWithRequest={(request) => {
if (request.url.startsWith('blob')) {
console.error('Link cannot be opened.');
return false;
}

if (request.url.startsWith('tel:') ||
request.url.startsWith('mailto:') ||
request.url.startsWith('sms:')
) {
Linking.openURL(request.url).catch(error => {
console.error('Failed to open Link: ' + error.message);
});
return false;
}
return true;
}}
onMessage={async (event: WebViewMessageEvent) => {
const { data } = event.nativeEvent;
if (data.startsWith('share:')) {
Expand Down

0 comments on commit 154b301

Please sign in to comment.