iOS: Use icon in header to create new channel (#80)

This commit is contained in:
Rodrigo Nascimento 2017-11-14 20:46:56 -02:00 committed by Guilherme Gazzo
parent 4e769920a1
commit 114c9727ce
2 changed files with 27 additions and 4 deletions

View File

@ -3,7 +3,7 @@ import { ListView } from 'realm/react-native';
import React from 'react';
import PropTypes from 'prop-types';
import Icon from 'react-native-vector-icons/Ionicons';
import { View, StyleSheet, TextInput, SafeAreaView } from 'react-native';
import { Platform, View, StyleSheet, TextInput, SafeAreaView } from 'react-native';
import { connect } from 'react-redux';
import * as actions from '../actions';
import * as server from '../actions/connect';
@ -78,6 +78,25 @@ export default class RoomsListView extends React.Component {
server: PropTypes.string
}
static navigationOptions = ({ navigation }) => {
if (Platform.OS !== 'ios') {
return;
}
const { params = {} } = navigation.state;
const headerRight = (
<Icon.Button
name='ios-create-outline'
color='blue'
size={26}
backgroundColor='transparent'
onPress={params.createChannel}
/>
);
return { headerRight };
};
constructor(props) {
super(props);
@ -94,6 +113,10 @@ export default class RoomsListView extends React.Component {
componentWillMount() {
this.data.addListener(this.updateState);
this.props.navigation.setParams({
createChannel: () => this._createChannel()
});
this.setState({
...this.state,
dataSource: ds.cloneWithRows(this.data)
@ -258,7 +281,7 @@ export default class RoomsListView extends React.Component {
style={styles.list}
renderRow={this.renderItem}
renderHeader={this.renderSearchBar}
contentOffset={{ x: 0, y: 20 }}
contentOffset={{ x: 0, y: 38 }}
enableEmptySections
keyboardShouldPersistTaps='always'
/>
@ -277,7 +300,7 @@ export default class RoomsListView extends React.Component {
<Banner />
<SafeAreaView style={styles.safeAreaView}>
{this.renderList()}
{this.renderCreateButtons()}
{Platform.OS === 'android' && this.renderCreateButtons()}
</SafeAreaView>
</View>)
}

View File

@ -248,7 +248,7 @@ export default class RoomsListView extends React.Component {
style={styles.list}
renderRow={this.renderItem}
renderHeader={this.renderHeader}
contentOffset={{ x: 0, y: this.props.users.length > 0 ? 40 : 20 }}
contentOffset={{ x: 0, y: this.props.users.length > 0 ? 38 : 0 }}
enableEmptySections
keyboardShouldPersistTaps='always'
/>