Skip to content

Commit 947b3a4

Browse files
authored
Merge pull request #134 from chrisglein/addDialogPackage
Use `react-native-content-dialog` for dialogs
2 parents eeb3036 + 1ba1b85 commit 947b3a4

10 files changed

+65
-212
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,5 @@ The app's settings are handled by a `SettingsContext` object, which has dialog U
105105
- Syntax Highlighting via [react-native-syntax-highlighter](https://github.com/conorhastings/react-native-syntax-highlighter)
106106
- Dependency patching via [patch-package](https://github.com/ds300/patch-package)
107107
- Storage via [react-native-async-storage](https://github.com/react-native-async-storage/async-storage)
108-
- Markdown rendering via [react-native-markdown-display](https://github.com/iamacup/react-native-markdown-display)
108+
- Markdown rendering via [react-native-markdown-display-updated](https://github.com/willmac321/react-native-markdown-display)
109+
- Dialogs via [react-native-content-dialog](https://github.com/chrisglein/react-native-content-dialog)

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
},
1414
"dependencies": {
1515
"@react-native-async-storage/async-storage": "^1.17.11",
16-
"@react-native-clipboard/clipboard": "^1.11.2",
17-
"@react-native-picker/picker": "^2.2.1",
16+
"@react-native-clipboard/clipboard": "^1.12.1",
17+
"@react-native-picker/picker": "^2.5.1",
1818
"patch-package": "^6.5.1",
1919
"postinstall-postinstall": "^2.1.0",
2020
"react": "18.2.0",
2121
"react-native": "0.71.0",
22-
"react-native-markdown-display": "^7.0.0-alpha.2",
22+
"react-native-content-dialog": "^0.2.0",
23+
"react-native-markdown-display-updated": "^7.0.0",
2324
"react-native-syntax-highlighter": "^2.1.0",
2425
"react-native-windows": "0.71.1"
2526
},

patches/@react-native-clipboard+clipboard+1.11.2.patch

-86
This file was deleted.

patches/@react-native-picker+picker+2.4.8.patch

-23
This file was deleted.

src/About.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from 'react-native';
77
import {Hyperlink} from './Controls';
88
import {
9-
DialogFrame,
9+
ContentDialog,
1010
} from './Popups';
1111
import {StylesContext} from './Styles';
1212
import VersionInfo from './NativeVersionInfo'
@@ -19,19 +19,19 @@ function AboutPopup({show, close}: AboutPopupProps): JSX.Element {
1919
const styles = React.useContext(StylesContext);
2020

2121
return (
22-
<DialogFrame
22+
<ContentDialog
2323
show={show}
2424
close={close}
25-
titleIcon="❔"
26-
title="About">
25+
title="About"
26+
defaultButtonIndex={0}>
2727
<Text>Version: <Text style={{fontWeight: 'bold'}}>{VersionInfo.getConstants().appVersion}</Text></Text>
2828
<View style={{flexDirection: 'row', gap: 4}}>
2929
<Text>Source code:</Text>
3030
<Hyperlink
3131
text='GitHub'
3232
url='https://github.com/chrisglein/artificial-chat/'/>
3333
</View>
34-
</DialogFrame>
34+
</ContentDialog>
3535
);
3636
}
3737

src/AiResponse.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
import { StylesContext } from './Styles';
2323
import { FeedbackContext } from './Feedback';
2424
import Clipboard from '@react-native-clipboard/clipboard';
25-
import Markdown from 'react-native-markdown-display';
25+
import Markdown from 'react-native-markdown-display-updated';
2626

2727
type AiImageResponseProps = {
2828
imageUrls?: string[];

src/Feedback.tsx

+16-13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
TextInput,
88
View,
99
} from 'react-native';
10-
import {DialogFrame} from './Popups';
10+
import { ContentDialog } from './Popups';
1111
import { StylesContext } from './Styles';
1212
import VersionInfo from './NativeVersionInfo'
1313

@@ -29,28 +29,31 @@ function FeedbackPopup({show, close, isPositive, response}: FeedbackPopupProps):
2929
const [thisIsNotHelpful, setThisIsNotHelpful] = React.useState(false);
3030

3131
const buttons = [
32-
<Button
33-
accessibilityLabel="Submit feedback"
34-
title="Submit feedback"
35-
onPress={() => {
32+
{
33+
title: "Submit feedback",
34+
onPress: () => {
3635
const version = VersionInfo?.getConstants().appVersion;
3736
if (isPositive) {
3837
Linking.openURL(`https://github.com/chrisglein/artificial-chat/issues/new?template=feedback-positive.yaml&version=${version}&expected=${feedbackText}&response=${response}`);
3938
} else {
4039
Linking.openURL(`https://github.com/chrisglein/artificial-chat/issues/new?template=feedback-negative.yaml&version=${version}&expected=${feedbackText}&response=${response}`);
4140
}
42-
close();
43-
}}/>
44-
];
41+
}
42+
},
43+
{
44+
title: "Cancel",
45+
onPress: () => { }
46+
}
47+
];
4548

4649
return (
47-
<DialogFrame
50+
<ContentDialog
4851
show={show}
4952
close={close}
50-
titleIcon={isPositive ? "👍" : "👎"}
5153
titleIconStyle={{backgroundColor: isPositive ? 'green' : 'red'}}
52-
title="Provide additional feedback"
53-
buttons={buttons}>
54+
title={(isPositive ? "👍" : "👎") + "Provide additional feedback"}
55+
buttons={buttons}
56+
defaultButtonIndex={1}>
5457
<TextInput
5558
multiline={true}
5659
placeholder="What would the ideal answer have been?"
@@ -81,7 +84,7 @@ function FeedbackPopup({show, close, isPositive, response}: FeedbackPopupProps):
8184
<Text>This isn't helpful</Text>
8285
</View>
8386
</View>)}
84-
</DialogFrame>
87+
</ContentDialog>
8588
);
8689
}
8790

src/Popups.tsx

+4-49
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import React, { PropsWithChildren } from 'react';
1+
import React from 'react';
2+
import type { PropsWithChildren } from 'react';
23
import {
3-
Button,
44
Text,
55
View,
66
} from 'react-native';
7-
import {Popup} from 'react-native-windows';
87
import {StylesContext} from './Styles';
8+
import {ContentDialog} from 'react-native-content-dialog';
99

1010
type PopupsContextType = {
1111
showAbout: boolean,
@@ -20,51 +20,6 @@ const PopupsContext = React.createContext<PopupsContextType>({
2020
setShowSettings: () => {},
2121
});
2222

23-
type DialogFrameType = PropsWithChildren<{
24-
show: boolean,
25-
close: () => void;
26-
isLightDismissEnabled?: boolean,
27-
titleIcon: string,
28-
titleIconStyle?: any,
29-
title: string,
30-
buttons?: JSX.Element[],
31-
}>;
32-
function DialogFrame({children, show, close, isLightDismissEnabled, titleIcon, titleIconStyle, title, buttons}: DialogFrameType) {
33-
const styles = React.useContext(StylesContext);
34-
35-
const populatedButtons = buttons ?? [<Button
36-
accessibilityLabel='OK'
37-
title="OK"
38-
onPress={() => {
39-
close();
40-
}}/>];
41-
const buttonList = populatedButtons.map((button, index) => <View key={index}>{button}</View>);
42-
43-
return (
44-
<Popup
45-
isOpen={show}
46-
isLightDismissEnabled={isLightDismissEnabled ?? true}
47-
onDismiss={() => close()}>
48-
<View style={[styles.dialogBackground, {gap: 12}]}>
49-
<View style={{flexDirection: 'row', marginBottom: 4, gap: 4}}>
50-
<View style={[styles.dialogTitleIcon, titleIconStyle]}>
51-
<Text accessible={false}>{titleIcon}</Text>
52-
</View>
53-
<Text
54-
accessibilityRole="header"
55-
style={styles.dialogTitle}>
56-
{title}
57-
</Text>
58-
</View>
59-
{children}
60-
<View style={styles.dialogButtons}>
61-
{buttonList}
62-
</View>
63-
</View>
64-
</Popup>
65-
)
66-
}
67-
6823
type DialogSectionProps = PropsWithChildren<{
6924
header: string,
7025
}>;
@@ -80,4 +35,4 @@ function DialogSection({children, header}: DialogSectionProps): JSX.Element {
8035
);
8136
}
8237

83-
export { PopupsContext, DialogFrame, DialogSection }
38+
export { PopupsContext, ContentDialog, DialogSection }

src/Settings.tsx

+16-19
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import React from 'react';
22
import {
3-
Button,
4-
Switch,
53
Text,
64
TextInput,
75
View,
86
} from 'react-native';
97
import {
10-
DialogFrame,
8+
ContentDialog,
119
DialogSection,
1210
} from './Popups';
1311
import {
@@ -161,28 +159,27 @@ function SettingsPopup({show, close}: SettingsPopupProps): JSX.Element {
161159
}
162160

163161
const buttons = [
164-
<Button
165-
accessibilityLabel="OK"
166-
title="OK"
167-
onPress={() => {
162+
{
163+
title: "OK",
164+
onPress: () => {
168165
save();
169-
}}/>,
170-
<Button
171-
accessibilityLabel="Cancel"
172-
title="Cancel"
173-
onPress={() => {
166+
}
167+
},
168+
{
169+
title: "Cancel",
170+
onPress: () => {
174171
cancel();
175-
}}/>
176-
];
172+
}
173+
}
174+
];
177175

178176
return (
179-
<DialogFrame
177+
<ContentDialog
180178
show={show}
181179
close={cancel}
182-
isLightDismissEnabled={false}
183-
titleIcon="⚙️"
184180
title="OpenAI Settings"
185-
buttons={buttons}>
181+
buttons={buttons}
182+
defaultButtonIndex={0}>
186183
<View style={styles.dialogSectionsContainer}>
187184
<DialogSection header="Chat">
188185
<Text>AI Endpoint</Text>
@@ -250,7 +247,7 @@ function SettingsPopup({show, close}: SettingsPopupProps): JSX.Element {
250247
value={delayForArtificialResponse.toString()}/>
251248
</DialogSection>
252249
</View>
253-
</DialogFrame>
250+
</ContentDialog>
254251
);
255252
}
256253

0 commit comments

Comments
 (0)