Closed TheMonster1995 closed 6 years ago
@TheMonster1995 tried a sample code with react-navigation. It is working fine. Attaching a Gif.
Gif
Sample Code
import React from 'react'
import { StackNavigator } from 'react-navigation'
import { Button } from 'react-native'
import { Container, Header, View, Icon, Fab } from 'native-base';
class MyHomeScreen extends React.Component {
static navigationOptions = {
title: 'Home',
}
render() {
return (
<Container>
<View style={{ flex: 1 }}>
<Fab
active={true}
direction="up"
containerStyle={{}}
style={{ backgroundColor: '#5067FF' }}
position="bottomRight"
onPress={() => this.props.navigation.navigate('Profile')}>
<Icon name="share" />
</Fab>
</View>
</Container>
);
}
}
class MyProfileScreen extends React.Component {
static navigationOptions = {
title: 'Profile',
}
render() {
return (
<Container>
<View style={{ flex: 1 }}>
<Fab
active={true}
direction="up"
containerStyle={{}}
style={{ backgroundColor: '#5067FF' }}
position="bottomRight"
onPress={() => this.props.navigation.goBack()}>
<Icon name="share" />
</Fab>
</View>
</Container>
);
}
}
export default ModalStack = StackNavigator({
Home: {
screen: MyHomeScreen,
},
Profile: {
screen: MyProfileScreen,
},
});
It's okay untill you add a Content tag. Actually, the problem is not with it not functioning. It doesn't get clicked at all once a content component is added.
Should I open another issue and close this one?
@TheMonster1995 <Content/>
component is an implementation of ScrollView. Can you try setting prop contentContainerStyle={{ flex: 1 }}
for <Content/>
.
This temporarily fixes the problem. But if the list of the Views in the Content component extends the screen size (which in this case it most probably will), two things happen A) the FAB again becomes unavailable and B) the page won't be scrolled. And if the line you suggested contentContainerStyle={{ flex: 1 }}
is omitted, then the page does scroll, but the Fab goes to the very end of the list/scroll, and is still unavailable - can't be touched. There's a similar problem here.
@TheMonster1995 try placing FAB outside <Content/>
Gif
This to be documented #1427
The Fab still does nothing when placed outside of content. Removing the flat list fixes it. What is the solution? I mustn't be understanding something properly
import {
Body,
Button,
Container,
Content,
Fab,
Icon,
Left,
ListItem,
Right,
Text
} from 'native-base';
import { FlatList } from 'react-native';
import { type NavigationState } from 'react-navigation';
import React, { Component } from 'react';
import { userData } from '../services/UserService';
type Props = { navigation: NavigationState };
export class TasksScreen extends Component<Props> {
static navigationOptions = { title: 'Tasks' };
createTask() {
const { navigate } = this.props.navigation;
navigate('CreateTask');
}
editTask(entry) {
const { navigate } = this.props.navigation;
navigate('EditTask', {
task: entry.item,
index: entry.index,
})
}
render() {
return (
<Container>
<Fab
direction="left"
position="bottomRight"
onPress={ () => this.createTask() }>
<Icon name="add" />
</Fab>
<Content contentContainerStyle={{ flex: 1 }}>
<FlatList
data={ userData.currentUser().tasks }
renderItem={ entry =>
<ListItem itemDivider>
<Left />
<Body>
<Text>
{ entry.item.title }
</Text>
</Body>
<Right>
<Button transparent onPress={ () => this.editTask(entry) }>
<Icon active name="arrow-forward" />
</Button>
</Right>
</ListItem>
}
/>
</Content>
</Container>
);
}
}
try to use rounded Button instead of Fab and specify equals width and height. It worked for me
Just use FAB component after Flatlist then it will work perfectly
I'm trying to use FAB as a button - to navigate to another page and NOT open any extra FABs, and for some reason, it doesn't work.
react-native, react and native-base version
react-native: 0.50.3 react: 16.0.0 native-base: 2.3.6
Expected behavior
Navigate to the new page
Actual behavior
Nothing happens
Steps to reproduce (code snippet or screenshot)
Is the bug present in both ios and android or in any one of them?
It appears on android. I haven't tested it on iPhone yet.