1.0.39 • Published 4 years ago

react-native-dynamic-forms v1.0.39

Weekly downloads
15
License
MIT
Repository
-
Last release
4 years ago

DynamicForms is powered by React Native UI Kitten and Formik https://akveo.github.io/react-native-ui-kitten/docs/getting-started/what-is-ui-kitten#what-is-ui-kitten

https://jaredpalmer.com/formik

DOCS STILL UNDER CONSTRUCTION............

todos...

convert all components to styled components...

Follow instructions on their website to set up your application with UI Kitten.

Configure Application Root

Wrap the root component of your App into ApplicationProvider component. In your App.js:

import {
  ApplicationProvider,
  IconRegistry,
} from '@ui-kitten/components';
import {mapping, light} from '@eva-design/eva';
import {EvaIconsPack} from '@ui-kitten/eva-icons';

const App = () => (
    <ApplicationProvider
      mapping={mapping}
      theme={light}
    >
      <IconRegistry icons={EvaIconsPack} />
        {/* YOUR CODE */}
    </ApplicationProvider>
);

export default App;

Usage

import DynamicForm from '..';
import * as yup from 'yup';

const loginForm = {
  email: {
    type: 'textField',
    placeholder: 'email',
    title: 'Email',
    initialValue: '',
    keyboardType: 'email-address',
  },
  password: {
    type: 'textField',
    placeholder: 'password',
    title: 'Password',
    initialValue: '',
    secure: true,
  },

  checkbox: {
    type: 'checkboxField',
    placeholder: 'check',
    title: 'I agree with Terms & Conditions',
    initialValue: false,
    style: {},
    textStyle: {},
  },
};

const schema = yup.object({
  email: yup
    .string()
    .email()
    .required(),
  password: yup.string().required(),
  checkbox: yup
    .bool()
    .oneOf([true], 'You must agree with terms and conditions'),
});

const Login = ({}: LoginProps) => {
  return (
    <SafeAreaView style={{flex: 1}}>
      <DynamicForm
        form={loginForm}
        schema={schema}
        onSubmit={(values, fomikProps) => {
          console.log('VALUES', values);
          login(values.email, values.password, values.checkbox).then(() => {

          }).catch(e => {
            fomikProps.setError()
          })
        }}
        submitButtonText="Login"
      />
    </SafeAreaView>
  );
};

export default Login;

TextField

    referral_description: {
      type: "textField",
      multiline: true,
      placeholder: "",
      title: "Referral Description"
    }

Common Props

PropDescriptionDefaultRequired
typeType of field to render, valid values: 'textField', 'selectField', 'checkboxField', 'toggleField', 'radioField', 'datePickerField', 'avatarField', 'tagsInputField', 'pickerField', 'multiSelectPickerField', 'autoCompleteAddressField', 'buttonGroupField', 'fieldSection'NoneYes
placeholderPlaceholder string to display. Only valid in textFields, selectField, pickerField, ...NoneNo
titleTitle to display above the field.NoneNo
initialValueInitial Value of the field.NoneYes

Text Field Props

PropDescriptionDefaultRequired
multilineMake your textfield multiline.FalseNo
secureIf you want your textfield to be of SecureEntry typeFalseNo
...otherTextInputPropsAny additional Input props will be passed down. refer to this link: https://akveo.github.io/react-native-ui-kitten/docs/components/input/overview#inputNoneNo

Select Field Props

PropDescriptionDefaultRequired
optionsOptions of the select field. ex: {text: "Option 1"}, {text: "Option 2"}.NoneYes
...otherSelectPropsAny additional Select props will be passed down. refer to this link: https://akveo.github.io/react-native-ui-kitten/docs/components/select/api#selectNoneNo

Toggle Field Props

PropDescriptionDefaultRequired
...otherTogglePropsAny additional Toggle props will be passed down. refer to this link: https://akveo.github.io/react-native-ui-kitten/docs/components/toggle/overview#toggleNoneNo

Tags Input Field Props

PropDescriptionDefaultRequired
tagContainerStyleStyle Object for Container.NoneNo
tagIconStyleStyle Object for IconNoneNo
tagTextStyleStyle Object for TextNoneNo
renderCloseIconfunction to render Close Icon on tagNoneNo