0.0.5 • Published 6 years ago

react-native-settings-builder v0.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

react-native-settings-builder

npm dependencies

Settings components for React Native in style of native iOS or Android components. Uses react-native-dialogs for dialogs on Android.

Showcase

react-native-settings-components ios screenshot react-native-settings-components android screenshot

Install

npm install react-native-settings-components --save

or

yarn add react-native-settings-components

Usage

import {SettingsDividerShort, SettingsDividerLong, SettingsEditText, SettingsCategoryHeader, SettingsSwitch, SettingsPicker} from 'react-native-settings-components';

export default class App extends Component {

  constructor() {
    super();
    this.state = {
      username: '',
      allowPushNotifications: false,
      gender: '',
    };
  }

  render() {

    <ScrollView style={{flex: 1, backgroundColor: (Platform.OS === 'ios') ? colors.iosSettingsBackground : colors.white}}>

        <SettingsCategoryHeader title={'My Account'} textStyle={(Platform.OS === 'android') ? {color: colors.monza} : null}/>

        <SettingsDividerLong android={false}/>

        <SettingsEditText
            title="Username"
            dialogDescription={'Enter your username.'}
            valuePlaceholder="..."
            negativeButtonTitle={'Cancel'}
            buttonRightTitle={'Save'}
            onSaveValue={(value) => {
                console.log('username:', value);
                this.setState({
                    username: value
                });
            }}
            value={this.state.username}
            dialogAndroidProps={{
                widgetColor: colors.monza,
                positiveColor: colors.monza,
                negativeColor: colors.monza,
            }}
        />

        <SettingsDividerShort/>

        <SettingsPicker
            title="Gender"
            dialogDescription={'Choose your gender.'}
            possibleValues={[
                {label: '...', value: ''},
                {label: 'male', value: 'male'},
                {label: 'female', value: 'female'},
                {label: 'other', value: 'other'}
            ]}
            negativeButtonTitle={'Cancel'}
            buttonRightTitle={'Save'}
            onSaveValue={value => {
                console.log('gender:', value);
                this.setState({
                    gender: value
                });
            }}
            value={this.state.gender}
            styleModalButtonsText={{color: colors.monza}}
        />

        ...

        <SettingsSwitch
            title={'Allow Push Notifications'}
            onSaveValue={(value) => {
                console.log('allow push notifications:', value);
                this.setState({
                    allowPushNotifications: value
                });
            }}
            value={this.state.allowPushNotifications}
            thumbTintColor={(this.state.allowPushNotifications) ? colors.switchEnabled : colors.switchDisabled}
        />

        ...

      </ScrollView>

    }

}

const colors = {
  iosSettingsBackground: 'rgb(235,235,241)',
  white: '#FFFFFF',
  monza: '#C70039',
  switchEnabled: (Platform.OS === 'android') ? '#C70039' : null,
  switchDisabled: (Platform.OS === 'android') ? '#efeff3' : null,
  switchOnTintColor: (Platform.OS === 'android') ? 'rgba(199, 0, 57, 0.6)' : null,
  blueGem: '#27139A',
};

Props

SettingsCategoryHeader

PropDescriptionTypeDefault
titlecategory titleStringRequired
containercontainer props except styleObject{}
containerStylecontainer style propViewPropTypes{}
titlePropstitle props except styleText Component Props / Object{}
titleStyletitle style propText PropTypes{}

SettingsDividerLong

PropDescriptionTypeDefault
iosdisplay on iOSBooleantrue
androiddisplay on AndroidBooleantrue
dividerStyledivider style propViewPropTypes{}

SettingsDividerShort

PropDescriptionTypeDefault
iosdisplay on iOSBooleantrue
androiddisplay on AndroidBooleantrue
containerStylecontainer style propViewPropTypes{}
dividerStyledivider style propViewPropTypes{}

SettingsEditText

PropDescriptionTypeDefault
containerPropscontainer props except styleView Component Props{}
containerStylecontainer style propViewPropTypes{}
disabledOverlayStylecomponent overlay style if setting is disabledViewPropTypes{}
titlePropstitle props except styleText Component Props{}
titleStyletitle style propText PropTypes{}
titletitle of settingStringRequired
valuePropsvalue props except styleText Component Props{}
valueStylevalue style propText PropTypes{}
valuevalue of settingStringRequired
valuePlaceholderplaceholder if value is emptyString...
negativeButtonTitlenegative dialog buttons titleStringRequired
positiveButtonTitlepositive dialog buttons titleStringRequired
dialogDescriptiontext explaining what the user should do e.g.String`''
onSaveValuecallback to be invoked when the positive dialog button is pressedStringRequired
disabledwhether the settings value should be editable or notBooleanfalse
iosDialogInputTypeinput type of the dialog alert on iosStringplain-text
androidDialogPropsinput dialog props on android (see react-native-dialogs)String{}
touchablePropsprops of touchable opening input dialogString{}

SettingsPicker

PropDescriptionTypeDefault
containerPropscontainer props except styleView Component Props{}
containerStylecontainer style propViewPropTypes{}
disabledOverlayStylecomponent overlay style if setting is disabledViewPropTypes{}
titlePropstitle props except styleText Component Props{}
titleStyletitle style propText PropTypes{}
titletitle of settingStringRequired
valuePropsvalue props except styleText Component Props{}
valueStylevalue style propText PropTypes{}
valuevalue of settingStringRequired
possibleValuespicker valuesArray of objects in format {label: string, value: string}Required
valuePlaceholderplaceholder if value is emptyString...
negativeButtonTitlenegative dialog buttons titleStringRequired
positiveButtonTitlepositive dialog buttons titleStringRequired
dialogDescriptiontext explaining what the user should do e.g.String''
modalDescriptionStylemodal description style propText PropTypes{}
onSaveValuecallback to be invoked when the positive dialog button is pressedStringRequired
disabledwhether the settings value should be editable or notBooleanfalse
modalStylemodal ScrollView style propViewPropTypes{}
modalInnerStylemodal ScrollView inner View style propViewPropTypes{}
modalButtonsTitleStylemodal buttons style prop (positive and negative button)Text PropTypes{}
modalButtonsTitleNegativeStylevalue style propText PropTypes{}
modalButtonsTitlePositiveStylevalue style propText PropTypes{}

SettingsSwitch

PropDescriptionTypeDefault
containerPropscontainer props except styleView Component Props{}
containerStylecontainer style propViewPropTypes{}
disabledOverlayStylecomponent overlay style if setting is disabledViewPropTypes{}
titlePropstitle props except styleText Component Props{}
titleStyletitle style propText PropTypes{}
titletitle of settingStringRequired
switchWrapperPropsswitch wrapper props except styleView Component Props{}
switchWrapperStyleswitch wrapper style propView PropTypes{}
valuevalue of settingBooleanRequired
disabledwhether the settings value should be editable or notBooleanfalse
onSaveValuecallback to be invoked when the positive dialog button is pressedStringRequired
thumbTintColorswitch thumb tint colorColornull
onTintColorswitch background color when the switch is turned onColornull
switchPropsSwitch component props except the ones mentioned beforeSwitch Component Props{}

Example

There is an example app in the example directory.

Run iOS version by

git clone https://github.com/florianstahr/react-native-settings-components.git
npm install
react-native link
react-native run-ios