Skip to content

Commit 0b5ad56

Browse files
authored
fix: click outside close (#47)
* fix: click outside close * transparent
1 parent 1dacbda commit 0b5ad56

9 files changed

Lines changed: 45 additions & 21 deletions

File tree

apps/playground/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"expo": "54.0.29",
1616
"expo-status-bar": "3.0.9",
1717
"react": "19.1.0",
18-
"react-native": "0.81.5"
18+
"react-native": "0.81.5",
19+
"react-native-webview": "13.15.0"
1920
},
2021
"devDependencies": {
2122
"@babel/core": "7.28.5",

packages/react-native/src/components/survey-web-view.tsx

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,27 @@ import { RNConfig } from "@/lib/common/config";
33
import { Logger } from "@/lib/common/logger";
44
import { filterSurveys, getLanguageCode, getStyling } from "@/lib/common/utils";
55
import { SurveyStore } from "@/lib/survey/store";
6+
import type { TOverlay } from "@/types/common";
67
import { type TUserState, ZJsRNWebViewOnMessageData } from "@/types/config";
78
import type { TSurvey, SurveyContainerProps } from "@/types/survey";
8-
import React, { type JSX, useEffect, useRef, useState } from "react";
9+
import React, { type JSX, useEffect, useMemo, useRef, useState } from "react";
910
import { KeyboardAvoidingView, Modal, View, StyleSheet } from "react-native";
1011
import { WebView, type WebViewMessageEvent } from "react-native-webview";
1112

1213
const logger = Logger.getInstance();
1314
logger.configure({ logLevel: "debug" });
1415

16+
const getOverlayBackgroundColor = (overlay: TOverlay): string => {
17+
switch (overlay) {
18+
case "dark":
19+
return "rgba(51, 65, 85, 0.8)";
20+
case "light":
21+
return "rgba(148, 163, 184, 0.5)";
22+
case "none":
23+
return "transparent";
24+
}
25+
};
26+
1527
const surveyStore = SurveyStore.getInstance();
1628

1729
interface SurveyWebViewProps {
@@ -85,6 +97,15 @@ export function SurveyWebView(
8597
setShowSurvey(true);
8698
}, [props.survey.delay, isSurveyRunning, props.survey.name]);
8799

100+
const overlay = appConfig
101+
? (props.survey.projectOverwrites?.overlay ?? appConfig.get().environment.data.project.overlay)
102+
: "none";
103+
104+
const modalContainerStyle = useMemo(
105+
() => [styles.modalContainer, { backgroundColor: getOverlayBackgroundColor(overlay) }],
106+
[overlay]
107+
);
108+
88109
if (!appConfig) {
89110
return;
90111
}
@@ -114,8 +135,6 @@ export function SurveyWebView(
114135
const clickOutside =
115136
props.survey.projectOverwrites?.clickOutsideClose ??
116137
project.clickOutsideClose;
117-
const darkOverlay =
118-
props.survey.projectOverwrites?.darkOverlay ?? project.darkOverlay;
119138

120139
return (
121140
<Modal
@@ -127,7 +146,7 @@ export function SurveyWebView(
127146
setIsSurveyRunning(false);
128147
}}
129148
>
130-
<View style={styles.modalContainer}>
149+
<View style={modalContainerStyle}>
131150
<KeyboardAvoidingView
132151
behavior="padding"
133152
style={styles.keyboardAvoidingView}
@@ -145,9 +164,8 @@ export function SurveyWebView(
145164
languageCode,
146165
placement: surveyPlacement,
147166
appUrl: appConfig.get().appUrl,
148-
clickOutside:
149-
surveyPlacement === "center" ? clickOutside : true,
150-
darkOverlay,
167+
clickOutside,
168+
overlay,
151169
getSetIsResponseSendingFinished: (
152170
_f: (value: boolean) => void
153171
) => undefined,
@@ -269,7 +287,6 @@ export function SurveyWebView(
269287
const styles = StyleSheet.create({
270288
modalContainer: {
271289
flex: 1,
272-
backgroundColor: "rgba(0, 0, 0, 0.5)",
273290
},
274291
keyboardAvoidingView: {
275292
flex: 1,

packages/react-native/src/lib/common/tests/api.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ describe("api.ts", () => {
262262
id: "project123",
263263
recontactDays: 30,
264264
clickOutsideClose: true,
265-
darkOverlay: false,
265+
overlay: "none",
266266
placement: "bottomRight",
267267
inAppSurveyBranding: true,
268268
styling: {

packages/react-native/src/lib/common/tests/utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ describe("utils.ts", () => {
106106
id: mockProjectId,
107107
recontactDays: 7, // fallback if survey doesn't have it
108108
clickOutsideClose: false,
109-
darkOverlay: false,
109+
overlay: "none",
110110
placement: "bottomRight",
111111
inAppSurveyBranding: true,
112112
styling: { allowStyleOverwrite: false },
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type TOverlay = "none" | "light" | "dark";

packages/react-native/src/types/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export type TEnvironmentStateProject = Pick<
1111
| "id"
1212
| "recontactDays"
1313
| "clickOutsideClose"
14-
| "darkOverlay"
14+
| "overlay"
1515
| "placement"
1616
| "inAppSurveyBranding"
1717
> & {

packages/react-native/src/types/project.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { TOverlay } from "./common";
12
import type { TBaseStyling } from "./styling";
23

34
export type TProject = {
@@ -20,7 +21,7 @@ export type TProject = {
2021
};
2122
placement: "topLeft" | "topRight" | "bottomLeft" | "bottomRight"; // assumed from WidgetPlacement
2223
clickOutsideClose: boolean;
23-
darkOverlay: boolean;
24+
overlay: TOverlay;
2425
logo?: {
2526
url?: string;
2627
bgColor?: string;

packages/react-native/src/types/survey.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { TResponseData, TResponseUpdate } from "@/types/response";
22
import type { TFileUploadParams, TUploadFileConfig } from "@/types/storage";
3+
import type { TOverlay } from "./common";
34
import type { TProjectStyling } from "./project";
45

56
export type TJsFileUploadParams = {
@@ -45,7 +46,7 @@ export interface SurveyBaseProps {
4546
isCardBorderVisible?: boolean;
4647
startAtQuestionId?: string;
4748
clickOutside?: boolean;
48-
darkOverlay?: boolean;
49+
overlay?: TOverlay;
4950
hiddenFieldsRecord?: TResponseData;
5051
shouldResetQuestionId?: boolean;
5152
fullSizeCards?: boolean;
@@ -72,7 +73,7 @@ export interface SurveyContainerProps
7273
mode?: "modal" | "inline";
7374
containerId?: string;
7475
clickOutside?: boolean;
75-
darkOverlay?: boolean;
76+
overlay?: TOverlay;
7677
placement?: "bottomLeft" | "bottomRight" | "topLeft" | "topRight" | "center";
7778
action?: string;
7879
singleUseId?: string;
@@ -239,7 +240,7 @@ export type TSurvey = {
239240
| "center"
240241
| null;
241242
clickOutsideClose?: boolean | null;
242-
darkOverlay?: boolean | null;
243+
overlay?: TOverlay | null;
243244
} | null;
244245
languages: {
245246
default: boolean;

pnpm-lock.yaml

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)