aboutsummaryrefslogtreecommitdiff
path: root/src/components/onboarding/RegistrationWizard.tsx
blob: 3c6ca80ece43b18285b82d53b2835c60675bbd35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import React, {useEffect} from 'react';
import {View, StyleSheet, ViewProps, Keyboard} from 'react-native';
import * as Animatable from 'react-native-animatable';

interface RegistrationWizardProps extends ViewProps {
  step: 'one' | 'two' | 'three' | 'four' | 'five' | 'six' | 'seven';
}

const RegistrationWizard = (props: RegistrationWizardProps) => {
  const stepStyle = styles.step;
  const stepActiveStyle = [styles.step, styles.stepActive];

  // detects visibility of keyboard to display or hide wizard
  const [keyboardVisible, setKeyboardVisible] = React.useState(false);

  useEffect(() => {
    const showKeyboard = () => setKeyboardVisible(true);
    Keyboard.addListener('keyboardWillShow', showKeyboard);
    return () => Keyboard.removeListener('keyboardWillShow', showKeyboard);
  }, []);

  useEffect(() => {
    const hideKeyboard = () => setKeyboardVisible(false);
    Keyboard.addListener('keyboardWillHide', hideKeyboard);
    return () => Keyboard.removeListener('keyboardWillHide', hideKeyboard);
  }, []);

  return (
    <View {...props}>
      {!keyboardVisible && (
        <Animatable.View animation="fadeIn" duration={300}>
          <View style={styles.container}>
            <View style={props.step === 'one' ? stepActiveStyle : stepStyle} />
            <View style={styles.progress} />
            <View style={props.step === 'two' ? stepActiveStyle : stepStyle} />
            <View style={styles.progress} />
            <View
              style={props.step === 'three' ? stepActiveStyle : stepStyle}
            />
          </View>
        </Animatable.View>
      )}
      {keyboardVisible && (
        <Animatable.View animation="fadeOut" duration={300}>
          <View style={styles.container}>
            <View style={props.step === 'one' ? stepActiveStyle : stepStyle} />
            <View style={styles.progress} />
            <View style={props.step === 'two' ? stepActiveStyle : stepStyle} />
            <View style={styles.progress} />
            <View
              style={props.step === 'three' ? stepActiveStyle : stepStyle}
            />
          </View>
        </Animatable.View>
      )}
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flexDirection: 'row',
    justifyContent: 'center',
    alignItems: 'center',
  },
  step: {
    height: 18,
    width: 18,
    borderRadius: 9,
    borderWidth: 2,
    borderColor: '#e1f0ff',
  },
  stepActive: {
    backgroundColor: '#e1f0ff',
  },
  progress: {
    width: '35%',
    height: 2,
    backgroundColor: '#e1f0ff',
  },
});

export default RegistrationWizard;