mattermost-mobile/app/components/toast/index.tsx
Avinash Lingaloo 83c2cfff97
MM-41532 Gekidou Snack Bars (#6181)
* styling mobile

wip

* styling tablet

wip

tablet portrait

* removed offSetY

* Update en.json

* corrections from reviews

* removed space

* changed location to sourceScreen in post.tsx

* adjust width

* update message to text

* adding PanGesture

adding PanGesture- wip

PanGesture- wip

* able to touch through on iOS

* using EphemeralStore and listeners to discard overlays

* snack positioning and touches

* PanGesture- wip

* PanGesture- fine tuning the animation

PanGesture- wip

* removed toast keyword

* checks for ongoing animation

* dismiss overlay on navigating away

* dismiss overlay on navigating away

* dismiss overlay on tabPress

* dismiss overlay on tabPress

* cancelled timers on panning start

* add entering layoutAnimation

* add exitingg layoutAnimation

* fix  layoutAnimation

* fix styling

* eslint fix

* style fix

* fix timer not stopping

* revert changes made to the ephemeral store

* bumping the toast vertically by 4px

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2022-05-05 10:00:32 -04:00

86 lines
2.6 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {useMemo} from 'react';
import {StyleProp, Text, TextStyle, useWindowDimensions, View, ViewStyle} from 'react-native';
import Animated, {AnimatedStyleProp} from 'react-native-reanimated';
import CompassIcon from '@components/compass_icon';
import {useTheme} from '@context/theme';
import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme';
import {typography} from '@utils/typography';
type ToastProps = {
animatedStyle: AnimatedStyleProp<ViewStyle>;
children?: React.ReactNode;
iconName?: string;
message?: string;
style?: StyleProp<ViewStyle>;
textStyle?: StyleProp<TextStyle>;
}
export const TOAST_HEIGHT = 56;
const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => ({
center: {
alignItems: 'center',
width: '100%',
opacity: 0,
},
container: {
alignItems: 'center',
backgroundColor: theme.onlineIndicator,
borderRadius: 8,
elevation: 6,
flex: 1,
flexDirection: 'row',
height: TOAST_HEIGHT,
paddingLeft: 20,
paddingRight: 10,
shadowColor: changeOpacity('#000', 0.12),
shadowOffset: {width: 0, height: 4},
shadowRadius: 6,
},
flex: {flex: 1},
text: {
color: theme.buttonColor,
marginLeft: 10,
...typography('Body', 100, 'SemiBold'),
},
}));
const Toast = ({animatedStyle, children, style, iconName, message, textStyle}: ToastProps) => {
const theme = useTheme();
const styles = getStyleSheet(theme);
const dim = useWindowDimensions();
const containerStyle = useMemo(() => {
const totalMargin = 40;
const width = Math.min(dim.height, dim.width, 400) - totalMargin;
return [styles.container, {width}, style];
}, [dim, styles.container, style]);
return (
<Animated.View style={[styles.center, animatedStyle]}>
<Animated.View style={containerStyle}>
{Boolean(iconName) &&
<CompassIcon
color={theme.buttonColor}
name={iconName!}
size={18}
style={textStyle}
/>
}
{Boolean(message) &&
<View style={styles.flex}>
<Text style={[styles.text, textStyle]}>{message}</Text>
</View>
}
{children}
</Animated.View>
</Animated.View>
);
};
export default Toast;