| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- import {
- useLayoutEffect,
- useState
- } from "react";
- import {
- View
- } from "react-native";
- import stylesheet from "./stylesheet";
- import {
- NCoreUIKitLocalize,
- NCoreUIKitTheme,
- PageContainer,
- TextInput,
- Button,
- Header,
- Switch
- ,
- Text
- } from "ncore-ui-kit";
- import {
- useNavigation
- } from "@react-navigation/native";
- import type RootStackParamList from "../../navigation/type";
- import type {
- NativeStackNavigationProp
- } from "@react-navigation/native-stack";
- import type {
- ISwitchProps
- } from "ncore-ui-kit";
- const SPREAD_BEHAVIOURS: Array<ISwitchProps["spreadBehaviour"]> = [
- "baseline",
- "stretch",
- "free"
- ];
- const SwitchPage = () => {
- const {
- radiuses,
- borders,
- spaces,
- colors
- } = NCoreUIKitTheme.useContext();
- const {
- localize
- } = NCoreUIKitLocalize.useContext();
- const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
- const [
- spreadIndex,
- setSpreadIndex
- ] = useState<number>(0);
- const [
- title,
- setTitle
- ] = useState<string>("");
- const [
- subTitle,
- setSubTitle
- ] = useState<string>("");
- const [
- isDisabled,
- setIsDisabled
- ] = useState<boolean>(false);
- const [
- isActive,
- setIsActive
- ] = useState<boolean>(false);
- const [
- isLoading,
- setIsLoading
- ] = useState<boolean>(false);
- useLayoutEffect(() => {
- navigation.setOptions({
- header: () => (
- <Header
- title={localize("switch-title")}
- isWrapSafeareaContext={false}
- navigation={navigation}
- isGoBackEnable={true}
- />
- ),
- headerShown: true
- });
- }, []);
- return (
- <PageContainer
- scrollViewProps={{
- contentContainerStyle: stylesheet.scrollContent
- }}
- scrollViewStyle={[stylesheet.container]}
- isWorkWithHeaderSpace={false}
- isScrollable={true}
- >
- <View style={[stylesheet.contentContainer]}>
- <Text
- variant="bodyMediumSize"
- color="mid"
- style={{
- marginBottom: 20
- }}
- >
- {localize("switch-desc")}
- </Text>
- <View
- style={{
- borderColor: colors.content.border.subtle,
- marginBottom: spaces.spacingMd,
- borderRadius: radiuses.form,
- borderWidth: borders.line,
- padding: spaces.spacingMd,
- justifyContent: "center",
- alignItems: "center",
- minHeight: 120
- }}
- >
- <Switch
- title={title || localize("switch-exampleTitle")}
- spreadBehaviour={SPREAD_BEHAVIOURS[spreadIndex]}
- onPress={() => setIsActive(!isActive)}
- isDisabled={isDisabled}
- isLoading={isLoading}
- subTitle={subTitle}
- isActive={isActive}
- />
- </View>
- <TextInput
- placeholder={localize("switch-enterTitle")}
- title={localize("switch-titleLabel")}
- style={{
- marginBottom: spaces.spacingMd
- }}
- spreadBehaviour="stretch"
- onChangeText={setTitle}
- value={title}
- />
- <TextInput
- placeholder={localize("switch-enterSubTitle")}
- title={localize("switch-subTitleLabel")}
- style={{
- marginBottom: spaces.spacingMd
- }}
- onChangeText={setSubTitle}
- spreadBehaviour="stretch"
- value={subTitle}
- />
- <View
- style={{
- justifyContent: "space-between",
- gap: spaces.spacingMd,
- flexDirection: "row",
- flexWrap: "wrap",
- width: "100%"
- }}
- >
- <Button
- onPress={() => {
- setSpreadIndex((prev) =>
- prev + 1 > SPREAD_BEHAVIOURS.length - 1
- ? 0
- : prev + 1,
- );
- }}
- title={
- `${localize("switch-changeSpread")}: ${SPREAD_BEHAVIOURS[spreadIndex]}`
- }
- spreadBehaviour="free"
- />
- <View
- style={{
- justifyContent: "space-between",
- flexDirection: "row",
- alignItems: "center",
- flexWrap: "wrap",
- width: "100%"
- }}
- >
- <Switch
- title={localize("switch-toggleDisabled")}
- onPress={() => setIsDisabled(!isDisabled)}
- isActive={isDisabled}
- />
- <Switch
- title={localize("switch-toggleLoading")}
- onPress={() => setIsLoading(!isLoading)}
- isActive={isLoading}
- />
- <Switch
- title={localize("switch-toggleActive")}
- onPress={() => setIsActive(!isActive)}
- isActive={isActive}
- />
- </View>
- </View>
- </View>
- </PageContainer>
- );
- };
- export default SwitchPage;
|