question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FAB doesn't collapse properly in iOS

See original GitHub issue

“react”: “16.0.0-alpha.12” “react-native”: “0.48.1” “native-base”: “2.3.6” iOS 11

Actual behaviour

Using FAB in iOS, when clicking on child button and then change the FAB’s “active” to false, all buttons collapses except last one. (Note that there’s no problem when clicking on the actual FAB button to expand/collapse. The problem is just when trying to collapse everything by clicking on a child button)

Code

` import React, { Component } from ‘react’; import { View } from ‘react-native’; import { Fab, Icon, Button, Container, Content } from ‘native-base’;

class TmpScreen extends Component {

constructor() {
    super();
    this.state = {
        active: false
    };
}

render() {
    return(
        <Container>
            <View style={{flex: 1}}>
                <Fab
                    active={this.state.active}
                    direction="up"
                    position="bottomRight"
                    containerStyle={{  }}
                    style={{ backgroundColor: 'black' }}
                    onPress={() => this.setState({ active: !this.state.active })}
                >
                    <Icon name="add"/>
                    <Button
                        style={{backgroundColor: 'grey' }}
                        onPress={() => this.setState({ active: !this.state.active })}
                    >
                    </Button>
                    <Button
                        style={{backgroundColor: 'green'}}
                        onPress={() => this.setState({ active: !this.state.active })}
                    >
                    </Button>
                    <Button
                        style={{backgroundColor: 'red'}}
                        onPress={() => this.setState({ active: !this.state.active })}
                    >
                    </Button>
                </Fab>
            </View>
        </Container>
    )
}

} `

Steps to reproduce (code snippet or screenshot)

  • Click on FAB
  • Click on one of its children buttons

Screenshot of emulator/device

simulator screen shot - iphone 8 - 2018-02-05 at 17 00 15 simulator screen shot - iphone 8 - 2018-02-05 at 17 00 18

Is the bug present in both ios and android or in any one of them?

It’s working on Android.

Any other additional info which would help us debug the issue quicker.

Yes. If i make the direction ‘left’, the it’s working on iOS !!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
akhil-gacommented, Feb 9, 2018

@minaskamel As a workaround you can try this

Code

import React, { Component } from 'react';
import { Container, Header, View, Button, Icon, Fab } from 'native-base';
export default class FABExample extends Component {
  constructor() {
    super();
    this.state = {
      active: true
    };
  }
  render() {
    return (
      <Container>
        <Header />
        <View style={{ flex: 1 }}>
          <Fab
            active={this.state.active}
            direction="up"
            containerStyle={{}}
            style={{ backgroundColor: '#5067FF' }}
            position="bottomRight"
            onPress={() => this.setState({ active: !this.state.active })}>
            <Icon name="share" />
            {this.state.active ? <Button style={{ backgroundColor: '#34A34F' }} onPress={() => this.setState({ active: false })}>
              <Icon name="logo-whatsapp" />
            </Button> : null}
            {this.state.active ? <Button style={{ backgroundColor: '#3B5998' }} onPress={() => this.setState({ active: false })}>
              <Icon name="logo-facebook" />
            </Button> : null}
            {this.state.active ? <Button style={{ backgroundColor: '#DD5144' }} onPress={() => this.setState({ active: false })}>
              <Icon name="mail" />
            </Button> : null}
          </Fab>
        </View>
      </Container>
    );
  }
}

Gif

fab

1reaction
landoridcommented, Feb 8, 2020

Using the previous code losses the down animation.

Try this, it works as suggested by @SupriyaKalghatgi.

<Fab
  active={this.state.active}
  ref={component => this._fab = component}
  onPress={() => {
    const status = !this.state.active ;
    // Force the status update
    this._fab && (this._fab.state.active = status);
    this.setState({ active: status})
  }}>
  // Your buttons here
</Fab>

it worked for me with little changes; you should use this._fab._root.state.active

Read more comments on GitHub >

github_iconTop Results From Across the Web

Buttons: floating action button - Material Design
A floating action button (FAB) represents the primary action for a screen.
Read more >
collapse! Is the iPad and iPhone broken and black screen broken ...
The iPhone and iPad screens are all black, the touch screen does not respond ... “Hey, Siri, close the narration” → you can...
Read more >
Android: Expand/collapse animation - Stack Overflow
I took @LenaYan 's solution that didn't work properly to me (because it was transforming the View to a 0 height view before...
Read more >
ion-header - Ionic Framework
This can be done by adding two headers, one above the content and one inside of the content, and then setting the collapse...
Read more >
Collapse button NavigationView SideBar SwiftUI
I could not find a simple way to hide Collapse button on navigation bar. Also, as far as I checked the UI design...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found