|
| 1 | +import React, {Component} from 'react'; |
| 2 | +import {View, StyleSheet, Alert, ScrollView} from 'react-native'; |
| 3 | +import { |
| 4 | + Colors, |
| 5 | + Typography, |
| 6 | + TouchableOpacity, |
| 7 | + Text, |
| 8 | + FloatingButton |
| 9 | +} from 'react-native-ui-lib'; |
| 10 | + |
| 11 | +export default class FloatingButtonScreen extends Component { |
| 12 | + constructor(props) { |
| 13 | + super(props); |
| 14 | + |
| 15 | + this.state = { |
| 16 | + showButton: false |
| 17 | + }; |
| 18 | + } |
| 19 | + |
| 20 | + showButton = () => { |
| 21 | + this.setState({ |
| 22 | + showButton: true |
| 23 | + }); |
| 24 | + }; |
| 25 | + |
| 26 | + hideButton = () => { |
| 27 | + this.setState({ |
| 28 | + showButton: false |
| 29 | + }); |
| 30 | + }; |
| 31 | + |
| 32 | + notNow = () => { |
| 33 | + Alert.alert('Not Now!'); |
| 34 | + this.hideButton(); |
| 35 | + }; |
| 36 | + |
| 37 | + close = () => { |
| 38 | + Alert.alert('Closed.'); |
| 39 | + this.hideButton(); |
| 40 | + }; |
| 41 | + |
| 42 | + render() { |
| 43 | + return ( |
| 44 | + <View style={styles.container}> |
| 45 | + <Text text60 style={{textAlign: 'center'}}> |
| 46 | + Trigger Floating Button |
| 47 | + </Text> |
| 48 | + <View style={styles.buttonsContainer}> |
| 49 | + <TouchableOpacity |
| 50 | + style={[styles.triggerButton, {marginRight: 10}]} |
| 51 | + onPress={this.showButton} |
| 52 | + > |
| 53 | + <Text style={styles.triggerButtonText}>Show</Text> |
| 54 | + </TouchableOpacity> |
| 55 | + <TouchableOpacity |
| 56 | + style={styles.triggerButton} |
| 57 | + onPress={this.hideButton} |
| 58 | + > |
| 59 | + <Text style={styles.triggerButtonText}>Hide</Text> |
| 60 | + </TouchableOpacity> |
| 61 | + </View> |
| 62 | + |
| 63 | + <ScrollView showsVerticalScrollIndicator={false}> |
| 64 | + <View paddingT-20> |
| 65 | + <Text text70 style={{fontWeight: 'bold'}}> |
| 66 | + Scroll behind a FloatingButton |
| 67 | + </Text> |
| 68 | + <Text text80 marginT-10 style={{lineHeight: 24}}> |
| 69 | + Lorem Ipsum is simply dummy text of the printing and typesetting |
| 70 | + industry. Lorem Ipsum has been the industry standard dummy text |
| 71 | + ever since the 1500s, when an unknown printer took a galley of |
| 72 | + type and scrambled it to make a type specimen book. It has |
| 73 | + survived not only five centuries, but also the leap into |
| 74 | + electronic typesetting, remaining essentially unchanged. It was |
| 75 | + popularised in the 1960s with the release of Letraset sheets |
| 76 | + containing Lorem Ipsum passages, and more recently with desktop |
| 77 | + publishing software like Aldus PageMaker including versions of |
| 78 | + Lorem Ipsum. Contrary to popular belief, Lorem Ipsum is not simply |
| 79 | + random text. It has roots in a piece of classical Latin literature |
| 80 | + from 45 BC, making it over 2000 years old. Lorem Ipsum is simply |
| 81 | + dummy text of the printing and typesetting industry. Lorem Ipsum |
| 82 | + has been the industry standard dummy text ever since the 1500s, |
| 83 | + when an unknown printer took a galley of type and scrambled it to |
| 84 | + make a type specimen book. It has survived not only five |
| 85 | + centuries, but also the leap into electronic typesetting, |
| 86 | + remaining essentially unchanged. It was popularised in the 1960s |
| 87 | + with the release of Letraset sheets containing Lorem Ipsum |
| 88 | + passages, and more recently with desktop publishing software like |
| 89 | + Aldus PageMaker including versions of Lorem Ipsum. Contrary to |
| 90 | + popular belief, Lorem Ipsum is not simply random text. It has |
| 91 | + roots in a piece of classical Latin literature from 45 BC, making |
| 92 | + it over 2000 years old. |
| 93 | + </Text> |
| 94 | + </View> |
| 95 | + </ScrollView> |
| 96 | + |
| 97 | + <FloatingButton |
| 98 | + visible={this.state.showButton} |
| 99 | + button={{ |
| 100 | + label: 'Approve', |
| 101 | + onPress: this.close |
| 102 | + }} |
| 103 | + secondaryButton={{ |
| 104 | + label: 'Not now', |
| 105 | + onPress: this.notNow, |
| 106 | + color: Colors.red30 |
| 107 | + }} |
| 108 | + // bottomMargin={80} |
| 109 | + // hideBackgroundOverlay |
| 110 | + /> |
| 111 | + </View> |
| 112 | + ); |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +const styles = StyleSheet.create({ |
| 117 | + container: { |
| 118 | + padding: 30, |
| 119 | + paddingBottom: 0, |
| 120 | + flex: 1, |
| 121 | + backgroundColor: Colors.dark80 |
| 122 | + }, |
| 123 | + buttonsContainer: { |
| 124 | + flexDirection: 'row', |
| 125 | + justifyContent: 'center', |
| 126 | + margin: 20 |
| 127 | + }, |
| 128 | + triggerButton: { |
| 129 | + backgroundColor: Colors.dark10, |
| 130 | + width: 100, |
| 131 | + height: 30, |
| 132 | + borderWidth: 1, |
| 133 | + borderRadius: 4, |
| 134 | + justifyContent: 'center', |
| 135 | + alignItems: 'center' |
| 136 | + }, |
| 137 | + triggerButtonText: { |
| 138 | + color: Colors.white, |
| 139 | + ...Typography.text60 |
| 140 | + } |
| 141 | +}); |
0 commit comments