mattermost-mobile/app/screens/options_modal/options_modal.js
Chris Duarte 5c24375dae Reorganize sidebar channel items via pref (#1928)
* Reorganize sidebar channel items via pref
Add onItemPress


Add isModal prop


Add options modal for ungrouped sidebar


Filter zero item unreads from sections


Refactor unread filtering

Add SidebarSectionTypes to constants

Update mm-redux dep

Remove unused variable

* Fix lint errors. Update redux commit

* Add recent activity title

* Review feedback

* Fix issues after rebase

* Review feedback

* Change to use getAllDirectChannels

* Update redux library

* Fix lint error

* Update modal list snapshot
2018-11-09 13:06:21 -03:00

107 lines
2.8 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import {
Animated,
StyleSheet,
TouchableWithoutFeedback,
View,
} from 'react-native';
import EventEmitter from 'mattermost-redux/utils/event_emitter';
import {NavigationTypes} from 'app/constants';
import {emptyFunction} from 'app/utils/general';
import OptionsModalList from './options_modal_list';
const {View: AnimatedView} = Animated;
const DURATION = 200;
export default class OptionsModal extends PureComponent {
static propTypes = {
items: PropTypes.array.isRequired,
deviceHeight: PropTypes.number.isRequired,
deviceWidth: PropTypes.number.isRequired,
navigator: PropTypes.object,
onCancelPress: PropTypes.func,
onItemPress: PropTypes.func,
title: PropTypes.oneOfType([
PropTypes.string,
PropTypes.object,
]),
};
static defaultProps = {
onCancelPress: emptyFunction,
onItemPress: emptyFunction,
};
constructor(props) {
super(props);
this.state = {
top: new Animated.Value(props.deviceHeight),
};
}
componentDidMount() {
EventEmitter.on(NavigationTypes.NAVIGATION_CLOSE_MODAL, this.close);
Animated.timing(this.state.top, {
toValue: 0,
duration: DURATION,
}).start();
}
componentWillUnmount() {
EventEmitter.off(NavigationTypes.NAVIGATION_CLOSE_MODAL, this.close);
}
handleCancel = () => {
this.props.onCancelPress();
this.close();
};
close = () => {
Animated.timing(this.state.top, {
toValue: this.props.deviceHeight,
duration: DURATION,
}).start(() => {
this.props.navigator.dismissModal({
animationType: 'none',
});
});
};
render() {
const {
items,
onItemPress,
title,
} = this.props;
return (
<TouchableWithoutFeedback onPress={this.handleCancel}>
<View style={style.wrapper}>
<AnimatedView style={{height: this.props.deviceHeight, left: 0, top: this.state.top, width: this.props.deviceWidth}}>
<OptionsModalList
items={items}
onCancelPress={this.handleCancel}
onItemPress={onItemPress}
title={title}
/>
</AnimatedView>
</View>
</TouchableWithoutFeedback>
);
}
}
const style = StyleSheet.create({
wrapper: {
backgroundColor: 'rgba(0, 0, 0, 0.5)',
flex: 1,
},
});