Skip to content

Commit cbf111e

Browse files
committed
fix: convert all poll buttons to pressables
1 parent 7577f5c commit cbf111e

File tree

5 files changed

+39
-26
lines changed

5 files changed

+39
-26
lines changed

package/src/components/Poll/CreatePollContent.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useCallback, useEffect, useState } from 'react';
2-
import { StyleSheet, Switch, Text, TextInput, TouchableOpacity, View } from 'react-native';
2+
import { Pressable, StyleSheet, Switch, Text, TextInput, View } from 'react-native';
33

44
import { ScrollView } from 'react-native-gesture-handler';
55
import { useSharedValue } from 'react-native-reanimated';
@@ -94,7 +94,7 @@ export const CreatePollContent = () => {
9494
<>
9595
<View style={[styles.headerContainer, { backgroundColor: white }, headerContainer]}>
9696
<PollModalHeader onPress={() => closePollCreationDialog?.()} title={t('Create Poll')} />
97-
<TouchableOpacity
97+
<Pressable
9898
disabled={!isPollValid}
9999
onPress={() => {
100100
const currentPollOptions = Object.assign({}, pollOptions);
@@ -120,15 +120,15 @@ export const CreatePollContent = () => {
120120
: {}),
121121
});
122122
}}
123-
style={[styles.sendButton, sendButton]}
123+
style={({ pressed }) => [{ opacity: pressed ? 0.5 : 1 }, styles.sendButton, sendButton]}
124124
>
125125
<SendPoll
126126
height={24}
127127
pathFill={isPollValid ? '#005DFF' : '#B4BBBA'}
128128
viewBox='0 0 24 24'
129129
width={24}
130130
/>
131-
</TouchableOpacity>
131+
</Pressable>
132132
</View>
133133
<ScrollView
134134
contentContainerStyle={{ paddingBottom: 70 }}

package/src/components/Poll/components/Button.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useCallback, useState } from 'react';
2-
import { StyleSheet, Text, TouchableOpacity } from 'react-native';
2+
import { Pressable, StyleSheet, Text } from 'react-native';
33

44
import { Poll, PollOption } from 'stream-chat';
55

@@ -43,9 +43,12 @@ export const GenericPollButton = ({ onPress, title }: { onPress?: () => void; ti
4343
} = useTheme();
4444

4545
return (
46-
<TouchableOpacity onPress={onPress} style={[styles.container, container]}>
46+
<Pressable
47+
onPress={onPress}
48+
style={({ pressed }) => [{ opacity: pressed ? 0.5 : 1 }, styles.container, container]}
49+
>
4750
<Text style={[styles.text, { color: accent_dark_blue }, text]}>{title}</Text>
48-
</TouchableOpacity>
51+
</Pressable>
4952
);
5053
};
5154

@@ -77,9 +80,10 @@ export const AnswerListAddCommentButton = (props: PollButtonProps) => {
7780

7881
return (
7982
<>
80-
<TouchableOpacity
83+
<Pressable
8184
onPress={onPressHandler}
82-
style={[
85+
style={({ pressed }) => [
86+
{ opacity: pressed ? 0.5 : 1 },
8387
styles.answerListAddCommentContainer,
8488
{ backgroundColor: bg_user },
8589
buttonContainer,
@@ -88,7 +92,7 @@ export const AnswerListAddCommentButton = (props: PollButtonProps) => {
8892
<Text style={[styles.text, { color: accent_dark_blue }, text]}>
8993
{ownAnswer ? t<string>('Update your comment') : t<string>('Add a comment')}
9094
</Text>
91-
</TouchableOpacity>
95+
</Pressable>
9296
{showAddCommentDialog ? (
9397
<PollInputDialog
9498
closeDialog={() => setShowAddCommentDialog(false)}
@@ -136,9 +140,10 @@ export const VoteButton = ({ onPress, option }: PollVoteButtonProps) => {
136140
}, [message, onPress, poll, toggleVote]);
137141

138142
return ownCapabilities.castPollVote && !isClosed ? (
139-
<TouchableOpacity
143+
<Pressable
140144
onPress={onPressHandler}
141-
style={[
145+
style={({ pressed }) => [
146+
{ opacity: pressed ? 0.5 : 1 },
142147
styles.voteContainer,
143148
{
144149
backgroundColor: ownVotesByOptionId[option.id]
@@ -152,7 +157,7 @@ export const VoteButton = ({ onPress, option }: PollVoteButtonProps) => {
152157
]}
153158
>
154159
{ownVotesByOptionId[option.id] ? <Check height={15} pathFill='white' width={20} /> : null}
155-
</TouchableOpacity>
160+
</Pressable>
156161
) : null;
157162
};
158163

package/src/components/Poll/components/CreatePollOptions.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Dispatch, SetStateAction, useCallback, useMemo } from 'react';
2-
import { StyleSheet, Text, TextInput, TouchableOpacity, View } from 'react-native';
2+
import { Pressable, StyleSheet, Text, TextInput, View } from 'react-native';
33
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
44
import Animated, {
55
interpolate,
@@ -294,7 +294,7 @@ export const CreatePollOptions = (props: {
294294
/>
295295
))}
296296
</View>
297-
<TouchableOpacity
297+
<Pressable
298298
onPress={() => {
299299
const newIndex = pollOptions.length;
300300
currentOptionPositions.value = {
@@ -312,12 +312,17 @@ export const CreatePollOptions = (props: {
312312
};
313313
setPollOptions([...pollOptions, { text: '' }]);
314314
}}
315-
style={[styles.addOptionWrapper, { backgroundColor: bg_user }, addOption.wrapper]}
315+
style={({ pressed }) => [
316+
{ opacity: pressed ? 0.5 : 1 },
317+
styles.addOptionWrapper,
318+
{ backgroundColor: bg_user },
319+
addOption.wrapper,
320+
]}
316321
>
317322
<Text style={[styles.text, { color: black }, addOption.text]}>
318323
{t<string>('Add an option')}
319324
</Text>
320-
</TouchableOpacity>
325+
</Pressable>
321326
</View>
322327
);
323328
};

package/src/components/Poll/components/PollInputDialog.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import {
33
KeyboardAvoidingView,
44
Modal,
55
Platform,
6+
Pressable,
67
StyleSheet,
78
Text,
89
TextInput,
9-
TouchableOpacity,
1010
View,
1111
} from 'react-native';
1212

@@ -62,22 +62,25 @@ export const PollInputDialog = ({
6262
value={dialogInput}
6363
/>
6464
<View style={[styles.buttonContainer, buttonContainer]}>
65-
<TouchableOpacity onPress={closeDialog}>
65+
<Pressable
66+
onPress={closeDialog}
67+
style={({ pressed }) => ({ opacity: pressed ? 0.5 : 1 })}
68+
>
6669
<Text style={[styles.button, { color: accent_dark_blue }, button]}>
6770
{t<string>('Cancel')}
6871
</Text>
69-
</TouchableOpacity>
70-
<TouchableOpacity
72+
</Pressable>
73+
<Pressable
7174
onPress={() => {
7275
onSubmit(dialogInput);
7376
closeDialog();
7477
}}
75-
style={{ marginLeft: 32 }}
78+
style={({ pressed }) => ({ marginLeft: 32, opacity: pressed ? 0.5 : 1 })}
7679
>
7780
<Text style={[styles.button, { color: accent_dark_blue }, button]}>
7881
{t<string>('SEND')}
7982
</Text>
80-
</TouchableOpacity>
83+
</Pressable>
8184
</View>
8285
</View>
8386
</KeyboardAvoidingView>

package/src/components/Poll/components/PollModalHeader.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
2+
import { Pressable, StyleSheet, Text, View } from 'react-native';
33

44
import { useTheme } from '../../../contexts';
55
import { Back } from '../../../icons';
@@ -21,9 +21,9 @@ export const PollModalHeader = ({ onPress, title }: PollModalHeaderProps) => {
2121

2222
return (
2323
<View style={[styles.container, { backgroundColor: white }, container]}>
24-
<TouchableOpacity onPress={onPress}>
24+
<Pressable onPress={onPress} style={({ pressed }) => ({ opacity: pressed ? 0.5 : 1 })}>
2525
<Back height={24} pathFill={text_high_emphasis} viewBox='0 0 24 24' width={24} />
26-
</TouchableOpacity>
26+
</Pressable>
2727
<Text numberOfLines={1} style={[styles.title, { color: black }, titleStyle]}>
2828
{title}
2929
</Text>

0 commit comments

Comments
 (0)