mattermost-mobile/app/components/navigation_header/search.tsx
Elias Nahum 2621d921d6
[Gekidou] Performance & UI fixes (#6122)
* Fix search bar style

* MM-42983 Align mention badge on channel list item

* MM-42985 polish channel intro UI

* MM-42984 update fonts on 'Show' bottom sheet

* MM-42982 Increase tap area of back button on channel view

* Set StatusBar style based on theme sidebarBg

* Reconnect other WS after 20 seconds insted of 5

* Only fetch missing profiles for DM/GMs

* Database prepare records optimization

* Do not use fallbackUsername for storing GM/DM in the database

* fix filter for fetching missing dm/gm

* remove use of indexOf inside another loop

* remove use of includes inside another loop

* remove use of find inside another loop

* Add missing translations

* disable Flipper on iOS

* Remove Flipper code from AppDelegate

* feedback review

* trim DM display name to make sure is not empty

* fixing missing direct channels display name

* UI/UX feedback

* fix WS channel viewed and mark as unread

* Remove duplicate emojis from reaction bar
2022-04-04 17:09:26 -04:00

99 lines
3.5 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {useCallback, useMemo} from 'react';
import {FlatList, Platform, ScrollView, SectionList, VirtualizedList} from 'react-native';
import Animated, {useAnimatedStyle} from 'react-native-reanimated';
import Search, {SearchProps} from '@components/search';
import {ANDROID_HEADER_SEARCH_INSET, IOS_HEADER_SEARCH_INSET, SEARCH_INPUT_HEIGHT, TABLET_HEADER_SEARCH_INSET} from '@constants/view';
import {useIsTablet} from '@hooks/device';
import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme';
import {typography} from '@utils/typography';
type Props = SearchProps & {
defaultHeight: number;
forwardedRef?: React.RefObject<ScrollView | FlatList | SectionList>;
largeHeight: number;
scrollValue?: Animated.SharedValue<number>;
theme: Theme;
top: number;
}
const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => ({
container: {
backgroundColor: theme.sidebarBg,
height: SEARCH_INPUT_HEIGHT + 5,
justifyContent: 'flex-start',
paddingHorizontal: 20,
position: 'absolute',
width: '100%',
zIndex: 10,
},
inputContainerStyle: {
backgroundColor: changeOpacity(theme.sidebarText, 0.12),
},
inputStyle: {
color: theme.sidebarText,
},
}));
const NavigationSearch = ({
defaultHeight,
forwardedRef,
largeHeight,
scrollValue,
theme,
top,
...searchProps
}: Props) => {
const isTablet = useIsTablet();
const styles = getStyleSheet(theme);
const cancelButtonProps: SearchProps['cancelButtonProps'] = useMemo(() => ({
buttonTextStyle: {
color: changeOpacity(theme.sidebarText, 0.72),
...typography('Body', 100, 'Regular'),
},
color: theme.sidebarText,
}), [theme]);
const searchTop = useAnimatedStyle(() => {
return {marginTop: Math.max((-(scrollValue?.value || 0) + largeHeight), top)};
}, [defaultHeight, largeHeight, top]);
const onFocus = useCallback((e) => {
const searchInset = isTablet ? TABLET_HEADER_SEARCH_INSET : IOS_HEADER_SEARCH_INSET;
const offset = Platform.select({android: largeHeight + ANDROID_HEADER_SEARCH_INSET, default: defaultHeight + searchInset});
if (forwardedRef?.current && Math.abs((scrollValue?.value || 0)) <= top) {
if ((forwardedRef.current as ScrollView).scrollTo) {
(forwardedRef.current as ScrollView).scrollTo({y: offset, animated: true});
} else {
(forwardedRef.current as VirtualizedList<any>).scrollToOffset({
offset,
animated: true,
});
}
}
searchProps.onFocus?.(e);
}, [largeHeight, top]);
return (
<Animated.View style={[styles.container, searchTop]}>
<Search
{...searchProps}
cancelButtonProps={cancelButtonProps}
clearIconColor={theme.sidebarText}
inputContainerStyle={styles.inputContainerStyle}
inputStyle={styles.inputStyle}
onFocus={onFocus}
placeholderTextColor={changeOpacity(theme.sidebarText, Platform.select({android: 0.56, default: 0.72}))}
searchIconColor={theme.sidebarText}
selectionColor={theme.sidebarText}
/>
</Animated.View>
);
};
export default NavigationSearch;