Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support loading indicator for FAB #985

Merged
merged 5 commits into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions example/src/Examples/FABExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ class ButtonExample extends React.Component<Props, State> {
visible={this.state.visible}
disabled
/>

<FAB
icon="cancel"
label="Loading FAB"
style={styles.fab}
onPress={() => {}}
visible={this.state.visible}
loading
/>
<Portal>
<FAB.Group
open={this.state.open}
Expand Down
13 changes: 12 additions & 1 deletion src/components/FAB/FAB.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import color from 'color';
import * as React from 'react';
import { Animated, View, StyleSheet } from 'react-native';
import ActivityIndicator from '../ActivityIndicator';
import FABGroup from './FABGroup';
import Surface from '../Surface';
import CrossFadeIcon from '../CrossFadeIcon';
Expand Down Expand Up @@ -43,6 +44,10 @@ type Props = $RemoveChildren<typeof Surface> & {|
* Whether `FAB` is currently visible.
*/
visible: boolean,
/**
* Whether to show a loading indicator.
*/
loading?: boolean,
/**
* Function to execute on press.
*/
Expand Down Expand Up @@ -137,6 +142,7 @@ class FAB extends React.Component<Props, State> {
theme,
style,
visible,
loading,
...rest
} = this.props;
const { visibility } = this.state;
Expand Down Expand Up @@ -207,7 +213,12 @@ class FAB extends React.Component<Props, State> {
]}
pointerEvents="none"
>
<CrossFadeIcon source={icon} size={24} color={foregroundColor} />
{icon && loading !== true ? (
<CrossFadeIcon source={icon} size={24} color={foregroundColor} />
) : null}
{loading && label ? (
<ActivityIndicator size={18} color={foregroundColor} />
) : null}
{label ? (
<Text
style={[
Expand Down
1 change: 1 addition & 0 deletions typings/components/FAB.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface FABProps extends ViewProps {
color?: string;
disabled?: boolean;
visible?: boolean;
loading?: boolean;
onPress?: () => any;
theme?: ThemeShape;
}
Expand Down