Massive/Switch.tsx

39 lines
843 B
TypeScript
Raw Permalink Normal View History

import React from "react";
import { Platform, Pressable } from "react-native";
import { Switch as PaperSwitch, Text, useTheme } from "react-native-paper";
import { MARGIN } from "./constants";
2022-09-26 03:10:13 +00:00
2022-12-30 06:42:30 +00:00
function Switch({
2022-09-26 03:10:13 +00:00
value,
2022-12-24 06:55:38 +00:00
onChange,
title,
2022-09-26 03:10:13 +00:00
}: {
value?: boolean;
onChange: (value: boolean) => void;
title: string;
2022-09-26 03:10:13 +00:00
}) {
const { colors } = useTheme();
2022-09-26 03:10:13 +00:00
return (
<Pressable
2022-12-24 06:55:38 +00:00
onPress={() => onChange(!value)}
2022-09-26 03:10:13 +00:00
style={{
flexDirection: "row",
flexWrap: "wrap",
alignItems: "center",
marginBottom: Platform.OS === "ios" ? MARGIN : null,
2023-06-27 03:16:59 +00:00
}}
>
2022-09-26 03:10:13 +00:00
<PaperSwitch
color={colors.primary}
2023-06-27 03:16:59 +00:00
style={{ marginRight: MARGIN }}
2022-09-26 03:10:13 +00:00
value={value}
2022-12-24 06:55:38 +00:00
onValueChange={onChange}
2022-09-26 03:10:13 +00:00
/>
<Text>{title}</Text>
2022-09-26 03:10:13 +00:00
</Pressable>
);
2022-09-26 03:10:13 +00:00
}
2022-12-30 06:42:30 +00:00
export default React.memo(Switch);