Skip to content

Commit ab3c347

Browse files
committed
Migrate FloatingButton to TS
1 parent 6355505 commit ab3c347

File tree

7 files changed

+239
-190
lines changed

7 files changed

+239
-190
lines changed

demo/src/screens/componentScreens/FloatingButtonScreen.js

Lines changed: 0 additions & 126 deletions
This file was deleted.
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from 'react';
2+
import { ButtonPropTypes } from '../button';
3+
export interface FloatingButtonProps {
4+
/**
5+
* Whether the button is visible
6+
*/
7+
visible?: boolean;
8+
/**
9+
* Button element (all Button's component's props)
10+
*/
11+
button?: ButtonPropTypes;
12+
/**
13+
* Secondary button element (all Button's component's props)
14+
*/
15+
secondaryButton?: ButtonPropTypes;
16+
/**
17+
* The bottom margin of the button, or secondary button if passed
18+
*/
19+
bottomMargin?: number;
20+
/**
21+
* The duration of the button's animations (show/hide)
22+
*/
23+
duration?: number;
24+
/**
25+
* Whether to show/hide the button without animation
26+
*/
27+
withoutAnimation?: boolean;
28+
/**
29+
* Whether to show background overlay
30+
*/
31+
hideBackgroundOverlay?: boolean;
32+
}
33+
declare const _default: React.ComponentClass<FloatingButtonProps & {
34+
useCustomTheme?: boolean | undefined;
35+
}, any>;
36+
export default _default;

generatedTypes/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export {default as Text, TextPropTypes} from './components/text';
1212
export {default as TouchableOpacity, TouchableOpacityProps} from './components/touchableOpacity';
1313
export {default as Button, ButtonPropTypes} from './components/button';
1414
export {default as Checkbox, CheckboxPropTypes} from './components/checkbox';
15+
export {default as FloatingButton, FloatingButtonProps} from './components/floatingButton';
1516
export {default as Image, ImageProps} from './components/image';
1617
export {default as Overlay, OverlayTypes} from './components/overlay';
1718
export {default as RadioButton, RadioButtonPropTypes} from './components/radioButton/RadioButton';
@@ -29,7 +30,6 @@ export {
2930
ConnectionStatusBar,
3031
Dialog,
3132
Drawer,
32-
FloatingButton,
3333
FeatureHighlight,
3434
Hint,
3535
BaseInput,

0 commit comments

Comments
 (0)