@@ -11,11 +11,9 @@ import {
1111import {
1212 Chip ,
1313 Divider ,
14- ExtendedFloatingActionButton ,
15- FloatingActionButton ,
16- FloatingActionButtonMenu ,
17- FloatingActionButtonSize ,
18- FloatingActionButtonVariant ,
14+ FAB ,
15+ FABSize ,
16+ FABVariant ,
1917 List ,
2018 Switch ,
2119 Text ,
@@ -25,27 +23,31 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context';
2523
2624type FabType = 'icon' | 'extended' | 'extendedTransforming' | 'menu' ;
2725type FabPosition = 'start' | 'center' | 'end' ;
26+ type FabColor = FABVariant | 'custom' ;
2827
2928// Pixels of scroll change required to flip the transforming FAB. Avoids
3029// flicker from sub-pixel scroll jitter at the top of the list.
3130const SCROLL_DELTA_THRESHOLD = 4 ;
3231
32+ const CUSTOM_CONTAINER_COLOR = '#E91E63' ;
33+
3334const justifyContentByPosition = {
3435 start : 'flex-start' ,
3536 center : 'center' ,
3637 end : 'flex-end' ,
3738} as const satisfies Record < FabPosition , 'flex-start' | 'center' | 'flex-end' > ;
3839
39- const variants : FloatingActionButtonVariant [ ] = [
40+ const variants : FabColor [ ] = [
4041 'primary' ,
4142 'secondary' ,
4243 'tertiary' ,
4344 'tonalPrimary' ,
4445 'tonalSecondary' ,
4546 'tonalTertiary' ,
47+ 'custom' ,
4648] ;
4749
48- const sizes : FloatingActionButtonSize [ ] = [ 'default' , 'medium' , 'large' ] ;
50+ const sizes : FABSize [ ] = [ 'default' , 'medium' , 'large' ] ;
4951
5052const types : FabType [ ] = [ 'icon' , 'extended' , 'extendedTransforming' , 'menu' ] ;
5153
@@ -96,9 +98,11 @@ const FABExample = () => {
9698 const { colors } = useTheme ( ) ;
9799 const insets = useSafeAreaInsets ( ) ;
98100
99- const [ variant , setVariant ] =
100- React . useState < FloatingActionButtonVariant > ( 'tonalPrimary' ) ;
101- const [ size , setSize ] = React . useState < FloatingActionButtonSize > ( 'medium' ) ;
101+ const [ variant , setVariant ] = React . useState < FabColor > ( 'tonalPrimary' ) ;
102+ const activeVariant = variant === 'custom' ? undefined : variant ;
103+ const activeContainerColor =
104+ variant === 'custom' ? CUSTOM_CONTAINER_COLOR : undefined ;
105+ const [ size , setSize ] = React . useState < FABSize > ( 'medium' ) ;
102106 const [ type , setType ] = React . useState < FabType > ( 'icon' ) ;
103107 const [ position , setPosition ] = React . useState < FabPosition > ( 'end' ) ;
104108 const [ showFab , setShowFab ] = React . useState < boolean > ( true ) ;
@@ -188,19 +192,21 @@ const FABExample = () => {
188192 ] }
189193 >
190194 { type === 'icon' && (
191- < FloatingActionButton
195+ < FAB
192196 icon = "pencil"
193- variant = { variant }
197+ variant = { activeVariant }
198+ containerColor = { activeContainerColor }
194199 size = { size }
195200 visible = { showFab }
196201 onPress = { ( ) => { } }
197202 />
198203 ) }
199204 { ( type === 'extended' || type === 'extendedTransforming' ) && (
200- < ExtendedFloatingActionButton
205+ < FAB . Extended
201206 icon = "pencil"
202207 label = "Compose"
203- variant = { variant }
208+ variant = { activeVariant }
209+ containerColor = { activeContainerColor }
204210 size = { size }
205211 expanded = { type === 'extended' ? true : transformingExpanded }
206212 visible = { showFab }
@@ -209,36 +215,24 @@ const FABExample = () => {
209215 ) }
210216 </ View >
211217 { type === 'menu' ? (
212- < FloatingActionButtonMenu
218+ < FAB . Menu
213219 expanded = { menuExpanded }
214220 onDismiss = { ( ) => setMenuExpanded ( false ) }
215- horizontalAlignment = { position }
216- button = {
217- < FloatingActionButton
218- icon = "pencil"
219- variant = { variant }
220- size = { size }
221- visible = { showFab }
222- onPress = { ( ) => setMenuExpanded ( true ) }
223- />
224- }
225- >
226- < FloatingActionButtonMenu . Item
227- icon = "email"
228- label = "Send"
229- onPress = { ( ) => { } }
230- />
231- < FloatingActionButtonMenu . Item
232- icon = "bell"
233- label = "Remind me"
234- onPress = { ( ) => { } }
235- />
236- < FloatingActionButtonMenu . Item
237- icon = "star"
238- label = "Favorite"
239- onPress = { ( ) => { } }
240- />
241- </ FloatingActionButtonMenu >
221+ alignment = { position }
222+ trigger = { {
223+ icon : 'pencil' ,
224+ variant : activeVariant ,
225+ containerColor : activeContainerColor ,
226+ size,
227+ visible : showFab ,
228+ onPress : ( ) => setMenuExpanded ( true ) ,
229+ } }
230+ items = { [
231+ { icon : 'email' , label : 'Send' , onPress : ( ) => { } } ,
232+ { icon : 'bell' , label : 'Remind me' , onPress : ( ) => { } } ,
233+ { icon : 'star' , label : 'Favorite' , onPress : ( ) => { } } ,
234+ ] }
235+ />
242236 ) : null }
243237 </ View >
244238 ) ;
0 commit comments