Skip to content

Commit

Permalink
feat(handleTextInput): add specific HOC for controlling TextInput
Browse files Browse the repository at this point in the history
  • Loading branch information
Almouro committed Dec 15, 2018
1 parent 5576577 commit 3311b68
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/handleTextInput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { compose, withProps } from "recompose";
import { connect } from "formik";
import withInputTypeProps from "./withInputTypeProps";
import withFormikControl from "./withFormikControl";

const handleTextInput = compose(
withFormikControl,
withInputTypeProps,
connect,
withProps(
({
formik: { isSubmitting },
setFieldValue,
setFieldTouched,
onChangeText,
onBlur
}) => ({
onChangeText: text => {
setFieldValue(text);
if (onChangeText) onChangeText(text);
},
onBlur: () => {
// validate onBlur only while not submitting
// this prevents validating twice in succession when clicking 'done' on keyboard - first onSubmitEditing, then onBlur
setFieldTouched(true, !isSubmitting);
if (onBlur) onBlur();
}
})
)
);

export default handleTextInput;

0 comments on commit 3311b68

Please sign in to comment.