Skip to content

Commit 6c2aab6

Browse files
committed
feat: implement full results screen
1 parent 0bac549 commit 6c2aab6

3 files changed

Lines changed: 68 additions & 31 deletions

File tree

package/src/components/Poll/components/PollResults/PollOptionFullResults.tsx

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback } from 'react';
1+
import React, { useCallback, useMemo } from 'react';
22
import { FlatList, type FlatListProps, StyleSheet, Text, View } from 'react-native';
33

44
import { PollOption, PollVote as PollVoteClass } from 'stream-chat';
@@ -12,6 +12,7 @@ import {
1212
useTranslationContext,
1313
} from '../../../../contexts';
1414

15+
import { primitives } from '../../../../theme';
1516
import { usePollOptionVotesPagination } from '../../hooks/usePollOptionVotesPagination';
1617
import { usePollState } from '../../hooks/usePollState';
1718

@@ -35,32 +36,40 @@ export const PollOptionFullResultsContent = ({
3536

3637
const {
3738
theme: {
38-
colors: { bg_user, black, white },
3939
poll: {
40-
fullResults: { container, contentContainer, headerContainer, headerText },
40+
fullResults: { container, contentContainer, headerContainer, headerText, headerTitle },
4141
},
4242
},
4343
} = useTheme();
44+
const styles = useStyles();
4445

4546
const PollOptionFullResultsHeader = useCallback(
4647
() => (
4748
<View style={[styles.headerContainer, headerContainer]}>
48-
<Text style={[styles.headerText, { color: black }, headerText]}>
49+
<Text style={[styles.headerTitle, headerTitle]}>{option.text}</Text>
50+
<Text style={[styles.headerText, headerText]}>
4951
{t('{{count}} votes', { count: voteCountsByOption[option.id] ?? 0 })}
5052
</Text>
5153
</View>
5254
),
53-
[black, headerContainer, headerText, option.id, t, voteCountsByOption],
55+
[
56+
headerContainer,
57+
headerText,
58+
headerTitle,
59+
option.id,
60+
option.text,
61+
styles.headerContainer,
62+
styles.headerText,
63+
styles.headerTitle,
64+
t,
65+
voteCountsByOption,
66+
],
5467
);
5568

5669
return (
57-
<View style={[styles.container, { backgroundColor: white }, container]}>
70+
<View style={[styles.container, container]}>
5871
<FlatList
59-
contentContainerStyle={[
60-
styles.contentContainer,
61-
{ backgroundColor: bg_user },
62-
contentContainer,
63-
]}
72+
contentContainerStyle={[styles.contentContainer, contentContainer]}
6473
data={votes}
6574
keyExtractor={(item) => `option_full_results_${item.id}`}
6675
ListHeaderComponent={PollOptionFullResultsHeader}
@@ -91,16 +100,42 @@ export const PollOptionFullResults = ({
91100
</PollContextProvider>
92101
);
93102

94-
const styles = StyleSheet.create({
95-
container: { flex: 1 },
96-
contentContainer: {
97-
borderRadius: 12,
98-
marginBottom: 8,
99-
marginHorizontal: 16,
100-
marginTop: 16,
101-
paddingHorizontal: 16,
102-
paddingVertical: 12,
103-
},
104-
headerContainer: { flexDirection: 'row', justifyContent: 'flex-end', marginBottom: 8 },
105-
headerText: { fontSize: 16, marginLeft: 16 },
106-
});
103+
const useStyles = () => {
104+
const {
105+
theme: { semantics },
106+
} = useTheme();
107+
return useMemo(
108+
() =>
109+
StyleSheet.create({
110+
container: { flex: 1, padding: primitives.spacingMd },
111+
contentContainer: {
112+
backgroundColor: semantics.backgroundCoreSurfaceCard,
113+
borderRadius: primitives.radiusLg,
114+
marginBottom: primitives.spacingMd,
115+
padding: primitives.spacingMd,
116+
},
117+
headerContainer: {
118+
flexDirection: 'row',
119+
justifyContent: 'space-between',
120+
alignItems: 'center',
121+
paddingBottom: primitives.spacingXs,
122+
},
123+
headerTitle: {
124+
flex: 1,
125+
fontSize: primitives.typographyFontSizeLg,
126+
lineHeight: primitives.typographyLineHeightRelaxed,
127+
fontWeight: primitives.typographyFontWeightSemiBold,
128+
color: semantics.textPrimary,
129+
paddingTop: primitives.spacingXs,
130+
},
131+
headerText: {
132+
fontSize: primitives.typographyFontSizeMd,
133+
lineHeight: primitives.typographyLineHeightNormal,
134+
fontWeight: primitives.typographyFontWeightSemiBold,
135+
color: semantics.textPrimary,
136+
marginLeft: primitives.spacingMd,
137+
},
138+
}),
139+
[],
140+
);
141+
};

package/src/components/Poll/components/PollResults/PollResultItem.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ export const ShowAllVotesButton = (props: ShowAllVotesButtonProps) => {
4949
setShowAllVotes(true);
5050
}, [message, onPress, option, poll]);
5151

52-
const {
53-
theme: {
54-
colors: { white },
55-
},
56-
} = useTheme();
52+
const styles = useStyles();
5753

5854
return (
5955
<>
@@ -68,8 +64,8 @@ export const ShowAllVotesButton = (props: ShowAllVotesButtonProps) => {
6864
onRequestClose={() => setShowAllVotes(false)}
6965
visible={showAllVotes}
7066
>
71-
<SafeAreaViewWrapper style={{ backgroundColor: white, flex: 1 }}>
72-
<PollModalHeader onPress={() => setShowAllVotes(false)} title={option.text} />
67+
<SafeAreaViewWrapper style={styles.safeArea}>
68+
<PollModalHeader onPress={() => setShowAllVotes(false)} title={t('Votes')} />
7369
<PollOptionFullResults message={message} option={option} poll={poll} />
7470
</SafeAreaViewWrapper>
7571
</Modal>
@@ -161,6 +157,10 @@ const useStyles = () => {
161157
color: semantics.textPrimary,
162158
marginLeft: primitives.spacingMd,
163159
},
160+
safeArea: {
161+
backgroundColor: semantics.backgroundElevationElevation1,
162+
flex: 1,
163+
},
164164
}),
165165
[semantics],
166166
);

package/src/contexts/themeContext/utils/theme.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,7 @@ export type Theme = {
837837
contentContainer: ViewStyle;
838838
headerContainer: ViewStyle;
839839
headerText: TextStyle;
840+
headerTitle: TextStyle;
840841
};
841842
inputDialog: {
842843
button: TextStyle;
@@ -1675,6 +1676,7 @@ export const defaultTheme: Theme = {
16751676
contentContainer: {},
16761677
headerContainer: {},
16771678
headerText: {},
1679+
headerTitle: {},
16781680
},
16791681
inputDialog: {
16801682
button: {},

0 commit comments

Comments
 (0)