Skip to content

Commit

Permalink
fixing auto scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
egiwibowo13 committed Jun 7, 2021
1 parent 0fd6ba3 commit b00108d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rn-auto-scroll-form",
"version": "1.2.1",
"version": "1.2.2",
"description": "React Native component to handle auto scroll form to error field",
"main": "index.js",
"scripts": {
Expand Down
5 changes: 5 additions & 0 deletions src/Form.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {FormControllerProps, UseFormParams, FormContextParams, ScrollableViewProps} from './Form';

export function FormController<T>(props: FormControllerProps<T>)
export function useFormController<T>(params: UseFormParams<T>): FormContextParams<T>
export const ScrollableView: React.Component<ScrollableViewProps>
16 changes: 8 additions & 8 deletions src/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Count {
total: number;
}

interface FormContext<T> {
export interface FormContextParams<T> {
values: GenericObj<T>;
errors?: GenericObj<T>;
count: Count;
Expand All @@ -35,7 +35,7 @@ type SubmitParams<T> = {
firstErrAt?: string | null;
};

type UseFormParams<T> = {
export type UseFormParams<T> = {
initialValues: GenericObj<T>;
validationSchema: any;
onSubmit: (params: SubmitParams<T>) => void;
Expand All @@ -48,10 +48,10 @@ type UseFormParams<T> = {
};

type FormProps<T> = {
children: (context: FormContext<T>) => React.FC<T>;
children: (context: FormContextParams<T>) => React.FC<T>;
} & UseFormParams<T>;

type ScrollableViewProps = {
export type ScrollableViewProps = {
children: React.ReactNode;
} & ScrollViewProps;

Expand Down Expand Up @@ -98,7 +98,7 @@ function useCount(
};
}

export function useFormController<T>(params: UseFormParams<T>): FormContext<T> {
export function useFormController<T>(params: UseFormParams<T>): FormContextParams<T> {
const {
initialValues,
validationSchema,
Expand Down Expand Up @@ -208,7 +208,7 @@ export function useFormController<T>(params: UseFormParams<T>): FormContext<T> {
};
}

const defaultContext: FormContext<any> = {
const defaultContext: FormContextParams<any> = {
values: {},
errors: {},
count: {
Expand All @@ -223,7 +223,7 @@ const defaultContext: FormContext<any> = {
};

export const FormContext =
React.createContext<FormContext<any>>(defaultContext);
React.createContext<FormContextParams<any>>(defaultContext);

const FormProvider = FormContext.Provider;
const FormConsumer = FormContext.Consumer;
Expand All @@ -246,7 +246,7 @@ export class ScrollableView extends React.Component<ScrollableViewProps> {
}
}

export const FormController = (props: FormControllerProps<any>) => {
export function FormController<T>(props: FormControllerProps<T>) {
const form = useFormController({
initialValues: props.initialValues,
validationSchema: props.validationSchema,
Expand Down
3 changes: 2 additions & 1 deletion src/helper.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import {findNodeHandle} from 'react-native';

export function isEmpty(value) {
return (
Expand All @@ -13,7 +14,7 @@ export const getPosition = (containerRef, ref, clb) => {
let result = {top: 0, left: 0, width: 0, height: 0};
if (ref.current && containerRef.current) {
ref.current.measureLayout(
containerRef.current,
findNodeHandle(containerRef.current),
(left, top, width, height) => {
result = {left, top, width, height};
clb(result);
Expand Down

0 comments on commit b00108d

Please sign in to comment.