Skip to content

Commit 92da2f4

Browse files
committed
fix: mirror switch in RTL mode
1 parent 75598cd commit 92da2f4

8 files changed

Lines changed: 50 additions & 5 deletions

File tree

examples/SampleApp/src/components/MenuDrawer.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { SafeAreaView } from 'react-native-safe-area-context';
1919
import { Group } from '../icons/Group.tsx';
2020
import { User } from '../icons/User';
2121
import { useLegacyColors } from '../theme/useLegacyColors';
22+
import { getRtlMirrorSwitchStyle } from '../utils/rtlMirrorSwitchStyle';
2223

2324
export const styles = StyleSheet.create({
2425
avatar: {
@@ -220,6 +221,7 @@ export const MenuDrawer = ({ navigation }: DrawerContentComponentProps) => {
220221
</View>
221222
<Switch
222223
onValueChange={setRTLEnabled}
224+
style={getRtlMirrorSwitchStyle()}
223225
thumbColor={white}
224226
trackColor={{
225227
false: grey,

examples/SampleApp/src/screens/GroupChannelDetailsScreen.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { LeaveGroup } from '../icons/LeaveGroup';
3434
import { Mute } from '../icons/Mute';
3535
import { Picture } from '../icons/Picture';
3636
import type { StackNavigatorParamList } from '../types';
37+
import { getRtlMirrorSwitchStyle } from '../utils/rtlMirrorSwitchStyle';
3738

3839
const MAX_VISIBLE_MEMBERS = 5;
3940

@@ -278,6 +279,7 @@ export const GroupChannelDetailsScreen: React.FC<GroupChannelDetailsProps> = ({
278279
trailing={
279280
<Switch
280281
onValueChange={handleMuteToggle}
282+
style={getRtlMirrorSwitchStyle()}
281283
trackColor={{
282284
false: semantics.controlToggleSwitchBg,
283285
true: semantics.accentPrimary,

examples/SampleApp/src/screens/OneOnOneChannelDetailScreen.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { Mute } from '../icons/Mute';
2626
import { Picture } from '../icons/Picture';
2727
import type { StackNavigatorParamList } from '../types';
2828
import { getUserActivityStatus } from '../utils/getUserActivityStatus';
29+
import { getRtlMirrorSwitchStyle } from '../utils/rtlMirrorSwitchStyle';
2930

3031
type OneOnOneChannelDetailScreenRouteProp = RouteProp<
3132
StackNavigatorParamList,
@@ -183,6 +184,7 @@ export const OneOnOneChannelDetailScreen: React.FC<Props> = ({
183184
trailing={
184185
<Switch
185186
onValueChange={handleMuteToggle}
187+
style={getRtlMirrorSwitchStyle()}
186188
trackColor={{
187189
false: semantics.controlToggleSwitchBg,
188190
true: semantics.accentPrimary,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { I18nManager, ViewStyle } from 'react-native';
2+
3+
/** Mirrors Switch horizontally in RTL so thumb/track match layout direction. */
4+
export function getRtlMirrorSwitchStyle(): Pick<ViewStyle, 'transform'> {
5+
return {
6+
transform: [{ scaleX: I18nManager.isRTL ? -1 : 1 }],
7+
};
8+
}

package/src/components/Poll/CreatePollContent.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
import { useMessageComposer } from '../../contexts/messageInputContext/hooks/useMessageComposer';
2525
import { useStateStore } from '../../hooks/useStateStore';
2626
import { primitives } from '../../theme';
27+
import { getRtlMirrorSwitchStyle } from '../../utils/rtlMirrorSwitchStyle';
2728

2829
const pollComposerStateSelector = (state: PollComposerState) => ({
2930
options: state.data.options,
@@ -171,7 +172,11 @@ export const CreatePollContent = () => {
171172
<Switch
172173
onValueChange={onAnonymousPollChangeHandler}
173174
value={isAnonymousPoll}
174-
style={[styles.optionCardSwitch, anonymousPoll.optionCardSwitch]}
175+
style={[
176+
styles.optionCardSwitch,
177+
getRtlMirrorSwitchStyle(),
178+
anonymousPoll.optionCardSwitch,
179+
]}
175180
/>
176181
</View>
177182
<View style={[styles.optionCard, suggestOption.wrapper]}>
@@ -185,7 +190,11 @@ export const CreatePollContent = () => {
185190
<Switch
186191
onValueChange={onAllowUserSuggestedOptionsChangeHandler}
187192
value={allowUserSuggestedOptions}
188-
style={[styles.optionCardSwitch, suggestOption.optionCardSwitch]}
193+
style={[
194+
styles.optionCardSwitch,
195+
getRtlMirrorSwitchStyle(),
196+
suggestOption.optionCardSwitch,
197+
]}
189198
/>
190199
</View>
191200
<View style={[styles.optionCard, addComment.wrapper]}>
@@ -199,7 +208,11 @@ export const CreatePollContent = () => {
199208
<Switch
200209
onValueChange={onAllowAnswersChangeHandler}
201210
value={allowAnswers}
202-
style={[styles.optionCardSwitch, addComment.optionCardSwitch]}
211+
style={[
212+
styles.optionCardSwitch,
213+
getRtlMirrorSwitchStyle(),
214+
addComment.optionCardSwitch,
215+
]}
203216
/>
204217
</View>
205218
</Animated.View>

package/src/components/Poll/components/MultipleAnswersField.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { MultipleVotesSettings } from './MultipleVotesSettings';
88
import { useTheme, useTranslationContext } from '../../../contexts';
99
import { useMessageComposer } from '../../../contexts/messageInputContext/hooks/useMessageComposer';
1010
import { primitives } from '../../../theme';
11+
import { getRtlMirrorSwitchStyle } from '../../../utils/rtlMirrorSwitchStyle';
1112

1213
export const MultipleAnswersField = () => {
1314
const [allowMultipleVotes, setAllowMultipleVotes] = useState<boolean>(false);
@@ -49,7 +50,11 @@ export const MultipleAnswersField = () => {
4950
<Switch
5051
onValueChange={onEnforceUniqueVoteHandler}
5152
value={allowMultipleVotes}
52-
style={[styles.optionCardSwitch, multipleAnswers.optionCardSwitch]}
53+
style={[
54+
styles.optionCardSwitch,
55+
getRtlMirrorSwitchStyle(),
56+
multipleAnswers.optionCardSwitch,
57+
]}
5358
/>
5459
</View>
5560
{allowMultipleVotes ? <MultipleVotesSettings /> : null}

package/src/components/Poll/components/MultipleVotesSettings.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { useStableCallback } from '../../../hooks';
1111
import { useStateStore } from '../../../hooks/useStateStore';
1212
import { Minus, Plus } from '../../../icons';
1313
import { primitives } from '../../../theme';
14+
import { getRtlMirrorSwitchStyle } from '../../../utils/rtlMirrorSwitchStyle';
1415
import { Button } from '../../ui';
1516

1617
const pollComposerStateSelector = (state: PollComposerState) => ({
@@ -152,7 +153,11 @@ export const MultipleVotesSettings = () => {
152153
<Switch
153154
onValueChange={onMaxVotesPerPersonHandler}
154155
value={allowMaxVotesPerPerson}
155-
style={[styles.optionCardSwitch, multipleAnswers.optionCardSwitch]}
156+
style={[
157+
styles.optionCardSwitch,
158+
getRtlMirrorSwitchStyle(),
159+
multipleAnswers.optionCardSwitch,
160+
]}
156161
/>
157162
</View>
158163
{allowMaxVotesPerPerson ? (
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { I18nManager, ViewStyle } from 'react-native';
2+
3+
/** Mirrors Switch horizontally in RTL so thumb/track match layout direction. */
4+
export function getRtlMirrorSwitchStyle(): Pick<ViewStyle, 'transform'> {
5+
return {
6+
transform: [{ scaleX: I18nManager.isRTL ? -1 : 1 }],
7+
};
8+
}

0 commit comments

Comments
 (0)