From fbc804b4cc7426cb38d3814da4b5e27422782007 Mon Sep 17 00:00:00 2001 From: meriadec Date: Wed, 26 Sep 2018 15:38:06 +0200 Subject: [PATCH] Add Button & ButtonContext --- .eslintrc | 1 + src/components/Button.js | 267 ++++++++++++++++++++++++++++++ src/context/ButtonUseTouchable.js | 12 ++ 3 files changed, 280 insertions(+) create mode 100644 src/components/Button.js create mode 100644 src/context/ButtonUseTouchable.js diff --git a/.eslintrc b/.eslintrc index 8fc815f074..3d16c4faad 100644 --- a/.eslintrc +++ b/.eslintrc @@ -42,6 +42,7 @@ "import/prefer-default-export": 0, "no-use-before-define": 0, "react/sort-comp": 0, + "react/jsx-boolean-value": 0, "react/prefer-stateless-function": 0, "react/jsx-filename-extension": 0, "react/no-multi-comp": 0, diff --git a/src/components/Button.js b/src/components/Button.js new file mode 100644 index 0000000000..bc5e08b74c --- /dev/null +++ b/src/components/Button.js @@ -0,0 +1,267 @@ +/* @flow */ + +import React, { PureComponent } from "react"; +import { RectButton } from "react-native-gesture-handler"; +import { + StyleSheet, + ActivityIndicator, + View, + Animated, + TouchableOpacity, +} from "react-native"; +import LText from "./LText"; +import ButtonUseTouchable from "../context/ButtonUseTouchable"; + +import colors from "../colors"; + +const WAIT_TIME_BEFORE_SPINNER = 150; +const BUTTON_HEIGHT = 48; +const ANIM_OFFSET = 20; +const ANIM_DURATION = 300; + +type ButtonType = "primary" | "secondary" | "tertiary" | "alert"; + +type BaseProps = { + type: ButtonType, + // when on press returns a promise, + // the button will toggle in a pending state and + // will wait the promise to complete before enabling the button again + // it also displays a spinner if it takes more than WAIT_TIME_BEFORE_SPINNER + onPress: () => ?Promise | any, + // text of the button + title: string, + containerStyle?: *, + titleStyle?: *, + IconLeft?: *, + disabled?: boolean, +}; + +type Props = BaseProps & { + useTouchable: boolean, +}; + +const ButtonWrapped = (props: BaseProps) => ( + + {useTouchable =>