Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn

- name: Install dependencies
run: yarn install --immutable

- name: Type check
run: yarn typecheck

- name: Build
run: yarn build
2 changes: 1 addition & 1 deletion examples/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Userback SDK Example",
"slug": "userback-sdk-example",
"version": "1.0.0",
"orientation": "portrait",
"orientation": "default",
"platforms": [
"ios",
"android"
Expand Down
4 changes: 2 additions & 2 deletions examples/ios/UserbackSDKExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@
SWIFT_OBJC_BRIDGING_HEADER = "UserbackSDKExample/UserbackSDKExample-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
};
name = Debug;
Expand All @@ -392,7 +392,7 @@
PRODUCT_NAME = UserbackSDKExample;
SWIFT_OBJC_BRIDGING_HEADER = "UserbackSDKExample/UserbackSDKExample-Bridging-Header.h";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
};
name = Release;
Expand Down
4 changes: 3 additions & 1 deletion examples/ios/UserbackSDKExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@
<string>arm64</string>
</array>
<key>UIRequiresFullScreen</key>
<false/>
<true/>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleDefault</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
Expand Down
10 changes: 10 additions & 0 deletions src/UserbackProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,14 @@ export function UserbackProvider({ children }: UserbackProviderProps) {
useEffect(() => {
const onStart = (cfg: UserbackConfig) => setConfig({ ...cfg });
const onStop = () => setConfig(null);
const onForceClose = () => setWidgetOpen(false);
UserbackSDK.on('_start', onStart);
UserbackSDK.on('_stop', onStop);
UserbackSDK.on('_forceClose', onForceClose);
return () => {
UserbackSDK.off('_start', onStart);
UserbackSDK.off('_stop', onStop);
UserbackSDK.off('_forceClose', onForceClose);
};
}, []);

Expand Down Expand Up @@ -142,6 +145,13 @@ export function UserbackProvider({ children }: UserbackProviderProps) {
webViewRef.current?.injectJavaScript(js);
}, []);

useEffect(() => {
const sub = Dimensions.addEventListener('change', () => {
inject(`(function(){window.dispatchEvent(new CustomEvent('userback:rotate'));})();true;`);
});
return () => sub.remove();
}, [inject]);

useEffect(() => {
if (config) {
UserbackSDK._attach(inject);
Expand Down
27 changes: 20 additions & 7 deletions src/UserbackSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class UserbackSDKClass extends Emitter {
private _ready = false;
private _pending: string[] = [];
private _inject: ((js: string) => void) | null = null;
private _formOpenTimeout: ReturnType<typeof setTimeout> | null = null;

public onWidgetConfigLoaded?: (config: Record<string, any>) => void;
public onWidgetResize?: (size: { width: number; height: number }) => void;
Expand Down Expand Up @@ -105,6 +106,7 @@ class UserbackSDKClass extends Emitter {
break;

case 'widget_resize':
this._clearFormOpenTimeout();
this.onWidgetResize?.(data.payload ?? {});
break;

Expand Down Expand Up @@ -191,26 +193,30 @@ class UserbackSDKClass extends Emitter {
}
}

private _clearFormOpenTimeout(): void {
if (this._formOpenTimeout !== null) {
clearTimeout(this._formOpenTimeout);
this._formOpenTimeout = null;
}
}

private _sendNativeEvent(event: Record<string, any>): void {
if (!this._inject) return;
if (event.type === 'log') {
const detail = { payload: { type: event.level, message: event.message } };
const detail = { payload: { type: event.level, message: event.message, mobileSDK: true }, mobileSDK: true };
const js = `(function(){window.dispatchEvent(new CustomEvent('userback:nativeLogEvent',{detail:${JSON.stringify(detail)}}));})();true;`;
this._inject(js);
} else {
const detail = { payload: event };
const detail = { payload: { ...event, mobileSDK: true }, mobileSDK: true };
const js = `(function(){window.dispatchEvent(new CustomEvent('userback:nativeNetworkEvent',{detail:${JSON.stringify(detail)}}));})();true;`;
this._inject(js);
}
}

/** @internal — called by UserbackProvider after capturing the screenshot */
_sendScreenshot(dataURL: string): void {
const message = JSON.stringify({
type: 'native_screenshot',
payload: { data_url: dataURL },
});
const js = `(function(){window.dispatchEvent(new CustomEvent('userback:nativeScreenshot',{detail:${message}}));})();true;`;
const detail = { type: 'native_screenshot', payload: { data_url: dataURL, mobileSDK: true }, mobileSDK: true };
const js = `(function(){window.dispatchEvent(new CustomEvent('userback:nativeScreenshot',{detail:${JSON.stringify(detail)}}));})();true;`;
if (this._inject) this._inject(js);
}

Expand All @@ -234,6 +240,7 @@ class UserbackSDKClass extends Emitter {
}

stop(): void {
this._clearFormOpenTimeout();
LogObserver.stop();
NetworkObserver.stop();
this._config = null;
Expand Down Expand Up @@ -263,7 +270,13 @@ class UserbackSDKClass extends Emitter {
}

openForm(mode = '', directTo?: string): void {
this._clearFormOpenTimeout();
this._run('openForm', [mode, directTo ?? null]);
this._formOpenTimeout = setTimeout(() => {
if (__DEV__) console.log('[Userback] openForm timed out — widget did not respond.');
this._clearFormOpenTimeout();
this.emit('_forceClose');
}, 5000);
}

openPortal(): void { this._run('openPortal'); }
Expand Down
3 changes: 1 addition & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2186,7 +2186,6 @@ __metadata:
resolution: "@userback/react-native-sdk@workspace:."
dependencies:
"@types/react": "npm:^18.0.0"
expo: "npm:~52.0.49"
react: "npm:18.3.1"
react-native: "npm:0.76.9"
react-native-view-shot: "npm:^3.8.0"
Expand Down Expand Up @@ -3816,7 +3815,7 @@ __metadata:
languageName: node
linkType: hard

"expo@npm:~52.0.0, expo@npm:~52.0.49":
"expo@npm:~52.0.0":
version: 52.0.49
resolution: "expo@npm:52.0.49"
dependencies:
Expand Down
Loading