mCloud Design Mobile

mCloud Design Mobile

  • Docs
  • API
  • Help
  • Blog

›Component

Component

  • Button
  • SegmentedControl
  • SearchBar
  • Radio
  • Checkbox
  • Badge
  • Marquee
  • Switch
  • InputItem
  • NoticeBar
  • Textarea
  • List
  • Card
  • Picker
  • Label
  • EmptyView
  • Stepper
  • Tabs
  • DatePicker
  • Modal
  • Avatar
  • ActionSheet
  • ShareSheet

First Category

  • Button
  • Fifth Document

Switch

滑动开关

Basic Example

import React, { useState } from 'react'
import { View, Text, StyleSheet } from 'react-native'
import { Switch } from 'mcloud-mobile';

const { SwitchItem } = Switch

export default () => {
    const [checked, onChange] = useState(false)
    return (
        <View style={styles.wrap}>
            <Text style={styles.boldTitle}>
                Switch
            </Text>
            <Text style={styles.title}>受控</Text>
            <Switch
                checked={checked}
                onChange={() => onChange(!checked)}
                style={styles.switch}
            />
            <Text style={styles.title}>默认选中</Text>
            <Switch
                checked
                style={styles.switch}
            />
            <Text style={styles.title}>不可选状态</Text>
            <Switch
                disabled
                hideLine
                style={styles.switch}
            />
            <Text style={styles.boldTitle}>
                SwitchItem
            </Text>
            <SwitchItem
                checked={checked}
                onChange={() => onChange(!checked)}
            >
                文本1(受控)
            </SwitchItem>
            <SwitchItem
                checked
            >
                文本2(默认选中)
            </SwitchItem>
            <SwitchItem
                disabled
                hideLine
            >
                <Text style={styles.desc}>文本3(不可选状态)</Text>
            </SwitchItem>
        </View>
    )
}

const styles = StyleSheet.create({
    wrap: {
        flex: 1,
        backgroundColor: '#E6E6E6',
    },
    title: {
        fontSize: 14,
        color: '#1F2530',
        paddingVertical: 10,
        paddingLeft: 15,
    },
    boldTitle: {
        fontSize: 16,
        color: '#1F2530',
        paddingVertical: 10,
        paddingLeft: 10,
        fontWeight: '500',
    },
    desc: {
        fontSize: 14,
        color: '#999',
    },
    switch: {
        marginBottom: 10,
        marginLeft: 15,
    },
})

Switch Props

属性说明类型默认值
checked默认值boolfalse
onChangechecked 值变化时调用的方法func() => { }
disabled默认值boolfalse

SwitchItem Props

有 Switch 的所有 props 属性,另外还有

属性说明类型默认值
hideLine是否隐藏下面的线Booleanfalse
← MarqueeInputItem →
  • Basic Example
  • Switch Props
  • SwitchItem Props
mCloud Design Mobile
Docs
Getting Started (or other categories)Guides (or other categories)API Reference (or other categories)
Community
User ShowcaseStack OverflowProject ChatTwitter
More
BlogGitHubStar
Facebook Open Source
Copyright © 2019 Your Name or Your Company Name