Skip to content

Commit ab790dd

Browse files
authored
Merge pull request #265 from iteratehq/sam/appearance-options
Add support for new appearance options (light, dark, or auto)
2 parents cf8b0da + 28e985a commit ab790dd

File tree

7 files changed

+88
-21
lines changed

7 files changed

+88
-21
lines changed

example/ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,4 +682,4 @@ SPEC CHECKSUMS:
682682

683683
PODFILE CHECKSUM: 329483eb6daf495a1eab8db2c188f13aaa25dcf9
684684

685-
COCOAPODS: 1.12.1
685+
COCOAPODS: 1.15.2

example/ios/example/Info.plist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@
7070
<string>UIInterfaceOrientationLandscapeLeft</string>
7171
<string>UIInterfaceOrientationLandscapeRight</string>
7272
</array>
73-
<key>UIUserInterfaceStyle</key>
74-
<string>Light</string>
7573
<key>UIViewControllerBasedStatusBarAppearance</key>
7674
<false/>
7775
</dict>

src/components/Prompt/Button.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,40 @@ import {
88
} from 'react-native';
99
import { Colors, Themes } from '../../constants';
1010
import Iterate from '../../iterate';
11+
import type { Survey } from '../../types';
1112

1213
interface Props {
1314
color: string;
1415
colorDark?: string;
1516
onPress: () => void;
1617
text: string;
18+
survey?: Survey;
1719
}
1820

1921
const PromptButton: (Props: Props) => JSX.Element = ({
2022
color,
2123
colorDark,
2224
onPress,
2325
text,
26+
survey,
2427
}) => {
25-
const theme = Appearance.getColorScheme();
28+
let backgroundColor;
29+
let textColor;
2630

27-
const backgroundColor =
28-
theme === Themes.Dark && colorDark != null ? colorDark : color;
29-
const textColor = theme === Themes.Dark ? Colors.Black : Colors.White;
31+
switch (survey?.appearance) {
32+
case Themes.Dark:
33+
backgroundColor = colorDark || color;
34+
textColor = Colors.Black;
35+
break;
36+
case Themes.Light:
37+
backgroundColor = color;
38+
textColor = Colors.White;
39+
break;
40+
default:
41+
Appearance.getColorScheme() === Themes.Dark
42+
? ((backgroundColor = colorDark || color), (textColor = Colors.Black))
43+
: ((backgroundColor = color), (textColor = Colors.White));
44+
}
3045

3146
return (
3247
<View>

src/components/Prompt/index.tsx

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,30 @@ const Prompt: (Props: Props) => JSX.Element = ({
107107
}, ANIMATION_DURATION);
108108
}, [dispatchShowSurvey, promptAnimation, survey]);
109109

110-
const theme = Appearance.getColorScheme();
111-
const promptBackgroundColor =
112-
theme === Themes.Dark ? Colors.LightBlack : Colors.White;
113-
const promptTextColor = theme === Themes.Dark ? Colors.White : Colors.Black;
114-
const shadowOpacity = theme === Themes.Dark ? 0.8 : 0.4;
110+
let promptBackgroundColor;
111+
let promptTextColor;
112+
let shadowOpacity;
113+
114+
switch (survey?.appearance) {
115+
case Themes.Dark:
116+
promptBackgroundColor = Colors.LightBlack;
117+
promptTextColor = Colors.White;
118+
shadowOpacity = 0.8;
119+
break;
120+
case Themes.Light:
121+
promptBackgroundColor = Colors.White;
122+
promptTextColor = Colors.Black;
123+
shadowOpacity = 0.4;
124+
break;
125+
default:
126+
Appearance.getColorScheme() === Themes.Dark
127+
? ((promptBackgroundColor = Colors.LightBlack),
128+
(promptTextColor = Colors.White),
129+
(shadowOpacity = 0.8))
130+
: ((promptBackgroundColor = Colors.White),
131+
(promptTextColor = Colors.Black),
132+
(shadowOpacity = 0.4));
133+
}
115134

116135
const paddingBottom = safeAreaInsets.bottom > 0 ? safeAreaInsets.bottom : 20;
117136

@@ -150,7 +169,7 @@ const Prompt: (Props: Props) => JSX.Element = ({
150169
]}
151170
>
152171
<View style={{ paddingBottom }}>
153-
<CloseButton onPress={onDismissAnimated} />
172+
<CloseButton onPress={onDismissAnimated} survey={survey} />
154173
{markdown.Render(survey?.prompt?.message ?? '', {
155174
body: [
156175
promptTextStyle,
@@ -175,6 +194,7 @@ const Prompt: (Props: Props) => JSX.Element = ({
175194
color={`${survey?.color || '#7457be'}`}
176195
colorDark={survey?.color_dark}
177196
onPress={showSurveyButtonClicked}
197+
survey={survey}
178198
/>
179199
</View>
180200
</View>
@@ -215,10 +235,27 @@ const styles = StyleSheet.create({
215235
},
216236
});
217237

218-
const CloseButton = ({ onPress }: { onPress: () => void }) => {
219-
const theme = Appearance.getColorScheme();
220-
const backgroundColor =
221-
theme === Themes.Dark ? Colors.LightBlack : Colors.Grey;
238+
const CloseButton = ({
239+
onPress,
240+
survey,
241+
}: {
242+
onPress: () => void;
243+
survey?: Survey;
244+
}) => {
245+
let backgroundColor;
246+
247+
switch (survey?.appearance) {
248+
case Themes.Dark:
249+
backgroundColor = Colors.LightBlack;
250+
break;
251+
case Themes.Light:
252+
backgroundColor = Colors.Grey;
253+
break;
254+
default:
255+
Appearance.getColorScheme() === Themes.Dark
256+
? (backgroundColor = Colors.LightBlack)
257+
: (backgroundColor = Colors.Grey);
258+
}
222259

223260
return (
224261
<TouchableHighlight

src/components/Survey.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ const SurveyView: (Props: Props) => JSX.Element = ({
105105

106106
// Add theme
107107
params.push(
108-
`theme=${useColorScheme() === Themes.Dark ? Themes.Dark : Themes.Light}`
108+
`theme=${
109+
useColorScheme() === Themes.Dark || survey?.appearance === Themes.Dark
110+
? Themes.Dark
111+
: Themes.Light
112+
}`
109113
);
110114

111115
params.push('absoluteURLs=true');
@@ -181,9 +185,20 @@ const SurveyView: (Props: Props) => JSX.Element = ({
181185
[dismiss, survey]
182186
);
183187

184-
const theme = Appearance.getColorScheme();
185-
const backgroundColor =
186-
theme === Themes.Dark ? Colors.LightBlack : Colors.White;
188+
let backgroundColor;
189+
190+
switch (survey?.appearance) {
191+
case Themes.Dark:
192+
backgroundColor = Colors.LightBlack;
193+
break;
194+
case Themes.Light:
195+
backgroundColor = Colors.Grey;
196+
break;
197+
default:
198+
Appearance.getColorScheme() === Themes.Dark
199+
? (backgroundColor = Colors.LightBlack)
200+
: (backgroundColor = Colors.Grey);
201+
}
187202

188203
// Only do this if we haven't already
189204
const addQueryParamScript = `if (!window.location.search) {

src/constants.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const Colors = {
1010
};
1111

1212
export const Themes = {
13+
Auto: 'auto',
1314
Light: 'light',
1415
Dark: 'dark',
1516
};

src/types.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export type PresentationStyle =
8484
| 'overFullScreen';
8585

8686
export type Survey = {
87+
appearance?: string;
8788
color?: string;
8889
color_dark?: string;
8990
company_id: string;

0 commit comments

Comments
 (0)