Skip to content

Commit

Permalink
fix: Articles are loading in external browser
Browse files Browse the repository at this point in the history
  • Loading branch information
muhsin-k authored Aug 2, 2023
2 parents cc6fc0c + 8e81ec8 commit 5327829
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
6 changes: 3 additions & 3 deletions examples/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const App = () => {
pricingPlan: 'paid',
status: 'active',
};
const websiteToken = 'uDDidz9scvbDBcxjCfwdWJRZ';
const baseUrl = 'https://mobile.chatwoot.app';
const websiteToken = 'RY3LaFtwmkPhDdZVmRd4ektW';
const baseUrl = 'https://staging.chatwoot.com';
const [locale, setLocale] = useState('en');

return (
Expand Down Expand Up @@ -81,7 +81,7 @@ const App = () => {
websiteToken={websiteToken}
locale={locale}
baseUrl={baseUrl}
colorScheme="dark"
colorScheme="light"
closeModal={() => toggleWidget(false)}
isModalVisible={showWidget}
user={user}
Expand Down
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"test": "jest"
},
"dependencies": {
"@chatwoot/react-native-widget": "../chatwoot-react-native-widget-0.0.14.tgz",
"@chatwoot/react-native-widget": "../chatwoot-react-native-widget-0.0.16.tgz",
"@react-native-async-storage/async-storage": "^1.18.1",
"react": "18.2.0",
"react-native": "0.71.8",
Expand Down
6 changes: 3 additions & 3 deletions examples/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1062,9 +1062,9 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==

"@chatwoot/react-native-widget@../chatwoot-react-native-widget-0.0.14.tgz":
version "0.0.14"
resolved "../chatwoot-react-native-widget-0.0.14.tgz#66fa6465ca0c9027023c7ca9562ab27ad1835cb6"
"@chatwoot/react-native-widget@../chatwoot-react-native-widget-0.0.16.tgz":
version "0.0.16"
resolved "../chatwoot-react-native-widget-0.0.16.tgz#92fc5b787751147d4ee761f976c8f0e56e73cc85"
dependencies:
react-native-modal "^13.0.1"

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@chatwoot/react-native-widget",
"version": "0.0.14",
"version": "0.0.16",
"description": "React Native widget for Chatwoot",
"main": "index.js",
"scripts": {
Expand Down
11 changes: 10 additions & 1 deletion src/WebView.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const WebViewComponent = ({
customAttributes,
closeModal,
}) => {
const [currentUrl, setCurrentUrl] = React.useState(null);
let widgetUrl = `${baseUrl}/widget?website_token=${websiteToken}&locale=${locale}`;

if (cwCookie) {
Expand All @@ -50,7 +51,10 @@ const WebViewComponent = ({
});

const onShouldStartLoadWithRequest = (request) => {
const shouldRedirectToBrowser = !widgetUrl.includes(request.url);
const isMessageView = currentUrl && currentUrl.includes('#/messages');
const isAttachmentUrl = !widgetUrl.includes(request.url);
// Open the attachments only in the external browser
const shouldRedirectToBrowser = isMessageView && isAttachmentUrl;
if (shouldRedirectToBrowser) {
Linking.openURL(request.url);
return false;
Expand All @@ -59,6 +63,10 @@ const WebViewComponent = ({
return true;
};

const handleWebViewNavigationStateChange = (newNavState) => {
setCurrentUrl(newNavState.url);
};

return (
<WebView
source={{
Expand Down Expand Up @@ -89,6 +97,7 @@ const WebViewComponent = ({
style={styles.WebViewStyle}
injectedJavaScript={injectedJavaScript}
onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}
onNavigationStateChange={handleWebViewNavigationStateChange}
scrollEnabled
/>
);
Expand Down

0 comments on commit 5327829

Please sign in to comment.