Skip to content

Commit 5327829

Browse files
authored
fix: Articles are loading in external browser
2 parents cc6fc0c + 8e81ec8 commit 5327829

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

examples/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ const App = () => {
2424
pricingPlan: 'paid',
2525
status: 'active',
2626
};
27-
const websiteToken = 'uDDidz9scvbDBcxjCfwdWJRZ';
28-
const baseUrl = 'https://mobile.chatwoot.app';
27+
const websiteToken = 'RY3LaFtwmkPhDdZVmRd4ektW';
28+
const baseUrl = 'https://staging.chatwoot.com';
2929
const [locale, setLocale] = useState('en');
3030

3131
return (
@@ -81,7 +81,7 @@ const App = () => {
8181
websiteToken={websiteToken}
8282
locale={locale}
8383
baseUrl={baseUrl}
84-
colorScheme="dark"
84+
colorScheme="light"
8585
closeModal={() => toggleWidget(false)}
8686
isModalVisible={showWidget}
8787
user={user}

examples/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"test": "jest"
1212
},
1313
"dependencies": {
14-
"@chatwoot/react-native-widget": "../chatwoot-react-native-widget-0.0.14.tgz",
14+
"@chatwoot/react-native-widget": "../chatwoot-react-native-widget-0.0.16.tgz",
1515
"@react-native-async-storage/async-storage": "^1.18.1",
1616
"react": "18.2.0",
1717
"react-native": "0.71.8",

examples/yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,9 +1062,9 @@
10621062
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
10631063
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
10641064

1065-
"@chatwoot/react-native-widget@../chatwoot-react-native-widget-0.0.14.tgz":
1066-
version "0.0.14"
1067-
resolved "../chatwoot-react-native-widget-0.0.14.tgz#66fa6465ca0c9027023c7ca9562ab27ad1835cb6"
1065+
"@chatwoot/react-native-widget@../chatwoot-react-native-widget-0.0.16.tgz":
1066+
version "0.0.16"
1067+
resolved "../chatwoot-react-native-widget-0.0.16.tgz#92fc5b787751147d4ee761f976c8f0e56e73cc85"
10681068
dependencies:
10691069
react-native-modal "^13.0.1"
10701070

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@chatwoot/react-native-widget",
3-
"version": "0.0.14",
3+
"version": "0.0.16",
44
"description": "React Native widget for Chatwoot",
55
"main": "index.js",
66
"scripts": {

src/WebView.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const WebViewComponent = ({
3737
customAttributes,
3838
closeModal,
3939
}) => {
40+
const [currentUrl, setCurrentUrl] = React.useState(null);
4041
let widgetUrl = `${baseUrl}/widget?website_token=${websiteToken}&locale=${locale}`;
4142

4243
if (cwCookie) {
@@ -50,7 +51,10 @@ const WebViewComponent = ({
5051
});
5152

5253
const onShouldStartLoadWithRequest = (request) => {
53-
const shouldRedirectToBrowser = !widgetUrl.includes(request.url);
54+
const isMessageView = currentUrl && currentUrl.includes('#/messages');
55+
const isAttachmentUrl = !widgetUrl.includes(request.url);
56+
// Open the attachments only in the external browser
57+
const shouldRedirectToBrowser = isMessageView && isAttachmentUrl;
5458
if (shouldRedirectToBrowser) {
5559
Linking.openURL(request.url);
5660
return false;
@@ -59,6 +63,10 @@ const WebViewComponent = ({
5963
return true;
6064
};
6165

66+
const handleWebViewNavigationStateChange = (newNavState) => {
67+
setCurrentUrl(newNavState.url);
68+
};
69+
6270
return (
6371
<WebView
6472
source={{
@@ -89,6 +97,7 @@ const WebViewComponent = ({
8997
style={styles.WebViewStyle}
9098
injectedJavaScript={injectedJavaScript}
9199
onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}
100+
onNavigationStateChange={handleWebViewNavigationStateChange}
92101
scrollEnabled
93102
/>
94103
);

0 commit comments

Comments
 (0)