mattermost-mobile/app/screens/options_modal/options_modal.js
Shaz Amjad 64223efafe
MM-28474: Custom Sidebar Categories (#5460)
* Further cleanup and fixes

Tests clean-up

Tests fixed?

Plays nicely with threads

Tests fixed

Fixes ESR and show experimental flags

Failing test fixed

DM Fix

WIP: Bottom bar UX

Fixes for unreads

Failing test

Always show current channel

Create a channel in a category!

* Unreads on top

* Various fixes

* Improves category collapsing

* Passes correct ID through

* Tests cleanup

* Redo unreads and unread-button

* Reverts to just using ids

* More unreads back to using ids

* Uses appropriate selectors for pref updates

* Unreads sorted by recency

* Fixes test for recency

* Fixes re-rendering bug

* Code review updates, websocket event debounced
2021-09-20 14:11:57 -04:00

115 lines
3 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import PropTypes from 'prop-types';
import React, {PureComponent} from 'react';
import {
Animated,
Platform,
StyleSheet,
TouchableWithoutFeedback,
View,
} from 'react-native';
import {dismissModal} from '@actions/navigation';
import {NavigationTypes} from '@constants';
import EventEmitter from '@mm-redux/utils/event_emitter';
import {emptyFunction} from '@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,
onCancelPress: PropTypes.func,
title: PropTypes.oneOfType([
PropTypes.string,
PropTypes.object,
]),
subtitle: PropTypes.string,
};
static defaultProps = {
onCancelPress: 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,
useNativeDriver: false,
}).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,
useNativeDriver: false,
}).start(() => {
dismissModal();
});
};
onItemPress = () => {
if (Platform.OS === 'android') {
this.close();
} else {
dismissModal();
}
};
render() {
const {
items,
title,
subtitle,
} = 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={this.onItemPress}
title={title}
subtitle={subtitle}
/>
</AnimatedView>
</View>
</TouchableWithoutFeedback>
);
}
}
const style = StyleSheet.create({
wrapper: {
backgroundColor: 'rgba(0, 0, 0, 0.5)',
flex: 1,
},
});