Rocket.Chat.ReactNative/app/containers/UIKit/Overflow.tsx

88 lines
2.4 KiB
TypeScript
Raw Normal View History

2020-02-11 14:01:35 +00:00
import React, { useState } from 'react';
import { FlatList, StyleSheet, Text } from 'react-native';
2020-02-11 14:01:35 +00:00
import Popover from 'react-native-popover-view';
import Touchable from 'react-native-platform-touchable';
import { CustomIcon } from '../CustomIcon';
2020-02-11 14:01:35 +00:00
import ActivityIndicator from '../ActivityIndicator';
import { themes } from '../../lib/constants';
import { useTheme } from '../../theme';
2020-02-11 14:01:35 +00:00
import { BUTTON_HIT_SLOP } from '../message/utils';
import * as List from '../List';
import { IOption, IOptions, IOverflow } from './interfaces';
const keyExtractor = (item: any) => item.value;
2020-02-11 14:01:35 +00:00
const styles = StyleSheet.create({
menu: {
justifyContent: 'center'
},
option: {
padding: 8,
minHeight: 32
},
loading: {
padding: 0
}
});
const Option = ({ option: { text, value }, onOptionPress, parser, theme }: IOption) => (
2020-02-11 14:01:35 +00:00
<Touchable
onPress={() => onOptionPress({ value })}
feat: mobile color normalization (#5616) * chore: remove auxiliaryText color * chore: remove titleText * chore: password colors change * chore: use fontDefault on ActionSheet item * wip: type * chore: set custom icon default color * remove tintActive color * only set color when checked * remove icon color * remove tintActive * chore: remove STATUS_COLORS * chore: remove mentions colors * chore: remove switch color * chore: background color * chore: auxiliaryBackground * chore: one local colors * wip: some colors * wip: colors * wip: colors * wip: end colors * test: update * chore: fix some colors * chore: fix lint * chore: back to text props * chore: fix ts errors * revert * chore: fix lint * test: update snapshot * update storybook * cocoapods * fix app theme color * remove unused color * fix login service button color * remove unused color * unused backgroundColor * fix background color * fix transparent color * fix background color * wip: key * fix color * chore: revert to 1 tick * test: update * chore: use same color as front end * test: update * fix radius * fix background color * fix wrong color * change some colors * chore: update stories * chore: fix button style * chore: fix item color * lint * update snapshot * link * remove background color * change send to channel color * call icons * video conf colors * fix app default color * bottom sheet * remove background * two factor color * update tests * feat: add force-logout stream listener * remove icon colors * improve badge color * update tests * fix header colors * fix collapsible icon color * imagePreview color * wip * update test * lint --------- Co-authored-by: Diego Mello <diegolmello@gmail.com>
2024-04-18 10:19:54 +00:00
background={Touchable.Ripple(themes[theme].surfaceNeutral)}
style={styles.option}
>
2020-02-11 14:01:35 +00:00
<Text>{parser.text(text)}</Text>
</Touchable>
);
const Options = ({ options, onOptionPress, parser, theme }: IOptions) => (
2020-02-11 14:01:35 +00:00
<FlatList
data={options}
renderItem={({ item }) => <Option option={item} onOptionPress={onOptionPress} parser={parser} theme={theme} />}
keyExtractor={keyExtractor}
ItemSeparatorComponent={List.Separator}
2020-02-11 14:01:35 +00:00
/>
);
const touchable: { [key: string]: Touchable | null } = {};
2020-02-11 14:01:35 +00:00
export const Overflow = ({ element, loading, action, parser }: IOverflow) => {
const { theme } = useTheme();
const options = element?.options || [];
const blockId = element?.blockId || '';
2020-02-11 14:01:35 +00:00
const [show, onShow] = useState(false);
const onOptionPress = ({ value }: any) => {
2020-02-11 14:01:35 +00:00
onShow(false);
action({ value });
};
return (
<>
<Touchable
ref={ref => (touchable[blockId] = ref)}
feat: mobile color normalization (#5616) * chore: remove auxiliaryText color * chore: remove titleText * chore: password colors change * chore: use fontDefault on ActionSheet item * wip: type * chore: set custom icon default color * remove tintActive color * only set color when checked * remove icon color * remove tintActive * chore: remove STATUS_COLORS * chore: remove mentions colors * chore: remove switch color * chore: background color * chore: auxiliaryBackground * chore: one local colors * wip: some colors * wip: colors * wip: colors * wip: end colors * test: update * chore: fix some colors * chore: fix lint * chore: back to text props * chore: fix ts errors * revert * chore: fix lint * test: update snapshot * update storybook * cocoapods * fix app theme color * remove unused color * fix login service button color * remove unused color * unused backgroundColor * fix background color * fix transparent color * fix background color * wip: key * fix color * chore: revert to 1 tick * test: update * chore: use same color as front end * test: update * fix radius * fix background color * fix wrong color * change some colors * chore: update stories * chore: fix button style * chore: fix item color * lint * update snapshot * link * remove background color * change send to channel color * call icons * video conf colors * fix app default color * bottom sheet * remove background * two factor color * update tests * feat: add force-logout stream listener * remove icon colors * improve badge color * update tests * fix header colors * fix collapsible icon color * imagePreview color * wip * update test * lint --------- Co-authored-by: Diego Mello <diegolmello@gmail.com>
2024-04-18 10:19:54 +00:00
background={Touchable.Ripple(themes[theme].surfaceNeutral)}
2020-02-11 14:01:35 +00:00
onPress={() => onShow(!show)}
hitSlop={BUTTON_HIT_SLOP}
style={styles.menu}
>
{!loading ? (
feat: mobile color normalization (#5616) * chore: remove auxiliaryText color * chore: remove titleText * chore: password colors change * chore: use fontDefault on ActionSheet item * wip: type * chore: set custom icon default color * remove tintActive color * only set color when checked * remove icon color * remove tintActive * chore: remove STATUS_COLORS * chore: remove mentions colors * chore: remove switch color * chore: background color * chore: auxiliaryBackground * chore: one local colors * wip: some colors * wip: colors * wip: colors * wip: end colors * test: update * chore: fix some colors * chore: fix lint * chore: back to text props * chore: fix ts errors * revert * chore: fix lint * test: update snapshot * update storybook * cocoapods * fix app theme color * remove unused color * fix login service button color * remove unused color * unused backgroundColor * fix background color * fix transparent color * fix background color * wip: key * fix color * chore: revert to 1 tick * test: update * chore: use same color as front end * test: update * fix radius * fix background color * fix wrong color * change some colors * chore: update stories * chore: fix button style * chore: fix item color * lint * update snapshot * link * remove background color * change send to channel color * call icons * video conf colors * fix app default color * bottom sheet * remove background * two factor color * update tests * feat: add force-logout stream listener * remove icon colors * improve badge color * update tests * fix header colors * fix collapsible icon color * imagePreview color * wip * update test * lint --------- Co-authored-by: Diego Mello <diegolmello@gmail.com>
2024-04-18 10:19:54 +00:00
<CustomIcon size={18} name='kebab' color={themes[theme].fontDefault} />
) : (
<ActivityIndicator style={styles.loading} />
)}
2020-02-11 14:01:35 +00:00
</Touchable>
<Popover
isVisible={show}
// fromView exists in Popover Component
/* @ts-ignore*/
2020-02-11 14:01:35 +00:00
fromView={touchable[blockId]}
onRequestClose={() => onShow(false)}
>
2020-02-11 14:01:35 +00:00
<Options options={options} onOptionPress={onOptionPress} parser={parser} theme={theme} />
</Popover>
</>
);
};