forked from Ivasoft/mattermost-mobile
Compare commits
2 Commits
v2.0.0
...
MM-48420-v
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6c83fa8e3b | ||
|
|
09c6e8e036 |
@@ -1,14 +1,16 @@
|
|||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See LICENSE.txt for license information.
|
// See LICENSE.txt for license information.
|
||||||
|
|
||||||
import React from 'react';
|
import React, {useCallback} from 'react';
|
||||||
import {View, ScrollView} from 'react-native';
|
import {FlatList, ListRenderItemInfo, View} from 'react-native';
|
||||||
|
|
||||||
import {View as ViewConstants} from '@constants';
|
import {View as ViewConstants} from '@constants';
|
||||||
import {makeStyleSheetFromTheme} from '@utils/theme';
|
import {makeStyleSheetFromTheme} from '@utils/theme';
|
||||||
|
|
||||||
import SelectedOption from '../selected_option';
|
import SelectedOption from '../selected_option';
|
||||||
|
|
||||||
|
type SelectedOption = DialogOption | UserProfile | Channel
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
theme: Theme;
|
theme: Theme;
|
||||||
selectedOptions: DialogOption[] | UserProfile[] | Channel[];
|
selectedOptions: DialogOption[] | UserProfile[] | Channel[];
|
||||||
@@ -19,15 +21,12 @@ type Props = {
|
|||||||
const getStyleFromTheme = makeStyleSheetFromTheme(() => {
|
const getStyleFromTheme = makeStyleSheetFromTheme(() => {
|
||||||
return {
|
return {
|
||||||
container: {
|
container: {
|
||||||
marginLeft: 5,
|
marginHorizontal: 5,
|
||||||
|
marginRight: 5,
|
||||||
marginBottom: 5,
|
marginBottom: 5,
|
||||||
maxHeight: 100,
|
maxHeight: 100,
|
||||||
flexGrow: 0,
|
flexGrow: 0,
|
||||||
},
|
|
||||||
users: {
|
|
||||||
alignItems: 'flex-start',
|
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
flexWrap: 'wrap',
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -36,43 +35,47 @@ const SelectedOptions = ({
|
|||||||
theme, selectedOptions, onRemove, dataSource,
|
theme, selectedOptions, onRemove, dataSource,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const style = getStyleFromTheme(theme);
|
const style = getStyleFromTheme(theme);
|
||||||
const options: React.ReactNode[] = selectedOptions.map((optionItem) => {
|
|
||||||
let key: string;
|
|
||||||
|
|
||||||
switch (dataSource) {
|
|
||||||
case ViewConstants.DATA_SOURCE_USERS:
|
|
||||||
key = (optionItem as UserProfile).id;
|
|
||||||
break;
|
|
||||||
case ViewConstants.DATA_SOURCE_CHANNELS:
|
|
||||||
key = (optionItem as Channel).id;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
key = (optionItem as DialogOption).value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const renderItem = useCallback(({item}: ListRenderItemInfo<SelectedOption>) => {
|
||||||
return (
|
return (
|
||||||
<SelectedOption
|
<SelectedOption
|
||||||
key={key}
|
option={item}
|
||||||
option={optionItem}
|
|
||||||
theme={theme}
|
theme={theme}
|
||||||
dataSource={dataSource}
|
dataSource={dataSource}
|
||||||
onRemove={onRemove}
|
onRemove={onRemove}
|
||||||
/>);
|
/>);
|
||||||
});
|
}, [dataSource, onRemove, theme]);
|
||||||
|
|
||||||
|
const extractKey = useCallback((item: SelectedOption) => {
|
||||||
|
let key: string;
|
||||||
|
|
||||||
|
switch (dataSource) {
|
||||||
|
case ViewConstants.DATA_SOURCE_USERS:
|
||||||
|
key = (item as UserProfile)?.id;
|
||||||
|
break;
|
||||||
|
case ViewConstants.DATA_SOURCE_CHANNELS:
|
||||||
|
key = (item as Channel).id;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
key = (item as DialogOption).value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return key;
|
||||||
|
}, [dataSource]);
|
||||||
|
|
||||||
// eslint-disable-next-line no-warning-comments
|
|
||||||
// TODO Consider using a Virtualized List since the number of elements is potentially unbounded.
|
|
||||||
// https://mattermost.atlassian.net/browse/MM-48420
|
|
||||||
return (
|
return (
|
||||||
<ScrollView
|
<View style={[style.container]}>
|
||||||
style={style.container}
|
<FlatList
|
||||||
contentContainerStyle={style.scrollViewContent}
|
numColumns={3}
|
||||||
>
|
data={selectedOptions}
|
||||||
<View style={style.users}>
|
initialNumToRender={3}
|
||||||
{options}
|
renderItem={renderItem}
|
||||||
</View>
|
keyExtractor={extractKey}
|
||||||
</ScrollView>
|
/>
|
||||||
|
|
||||||
|
</View>
|
||||||
|
|
||||||
|
// </>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user