mattermost-mobile/app/utils/theme.js
Miguel Alatzar f79f9dc697
[MM-23761] [MM-25766] Add "More Messages" button (#4526)
* Add more messages button

* Update existing tests

* Various fixes:

* Use viewAreaCoveragePercentThreshold over itemVisiblePercentThreshold
* Remove currentUserId check when adding New Message line to postIds and
  instead update the channel last viewed time when an own post is received

* Update snapshots

* Add showMoreMessagesButton prop and default to false

* Android fixes

* Add tests

* Localize more messages text

* Use FormattedText

* i18 extract

* Style fixes

* Account for network indicator

* Fix for failing tests

* Various fixes:

* Set the unreadMessageCount when POST_UNREAD_SUCCESS is dispatched
  with a positive deltaMsgs
* Hide the more messages button when the unread count decreases or
  when the new message line is removed shortly after loading the
  channel

* No need for POST_UNREAD_SUCCESS if we manually call onViewableItemsChanged

* Reset unread count if current channel on channel mount

* Animate text opacity

* Compare indeces to determine when scrolling has ended

* Fix opacity animation trigger

* try with scrolling to the last rendered item

* Add onScrollEndIndex

* Improve animations

* Don't track moreCount in state

* Use moreText over prevNewMessageLineIndex to determine firstPage

* Update intl message format and call cancel in componentDidUpdate when needed

* Fix intl format

* Remove opacity animation and countText

* Fix pressed not being reset

* No need to separate intl func

* Return after resetting

* Fix accidental removal of setState call

* Reset pressed when newLineMessageIndex changes

* Use default windowSize and lower POST_CHUNK_SIZE and delays

* Queue a cancel timer that gets cleared only when the newMessageLineIndex changes

* Define uncancel func

* Increase cancelTimer delay

* Subtract read posts from unread count and account for retry indicator

* Add retry bar indicator tests

* Use props.unreadCount

* Fix handling of newMessageLineIndex change

* Fix handling of newMessageLineIndex change take 2

* Fix handling of newMessageLineIndex change take 3

* Use 'native' TouchableWithFeedback with dark overlay

* Fix handling of manually unread

* Update chunk and window sizes

* Fix hsl

* Update text only when newMessageLineIndex/endIndex is reached

* Don't delay cancel if when no more unreads

* Fixes for when opening the app

* No need to process viewableItems when unreadCount is 0

* Remove line

* Don't show if unreadCount is 0

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2020-07-09 13:30:30 -07:00

104 lines
2.6 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {StyleSheet} from 'react-native';
import tinyColor from 'tinycolor2';
import * as ThemeUtils from '@mm-redux/utils/theme_utils';
import {mergeNavigationOptions} from 'app/actions/navigation';
const MODAL_SCREENS_WITHOUT_BACK = [
'AddReaction',
'ChannelInfo',
'ClientUpgrade',
'CreateChannel',
'EditPost',
'ErrorTeamsList',
'MoreChannels',
'MoreDirectMessages',
'Permalink',
'SelectTeam',
'Settings',
'TermsOfService',
'UserProfile',
];
export function makeStyleSheetFromTheme(getStyleFromTheme) {
return ThemeUtils.makeStyleFromTheme((theme) => {
return StyleSheet.create(getStyleFromTheme(theme));
});
}
export const changeOpacity = ThemeUtils.changeOpacity;
export const blendColors = ThemeUtils.blendColors;
export function concatStyles(...styles) {
return [].concat(styles);
}
export function setNavigatorStyles(componentId, theme) {
const options = {
topBar: {
title: {
color: theme.sidebarHeaderTextColor,
},
background: {
color: theme.sidebarHeaderBg,
},
leftButtonColor: theme.sidebarHeaderTextColor,
rightButtonColor: theme.sidebarHeaderTextColor,
},
layout: {
componentBackgroundColor: theme.centerChannelBg,
},
};
if (!MODAL_SCREENS_WITHOUT_BACK.includes(componentId)) {
options.topBar.backButton = {
color: theme.sidebarHeaderTextColor,
};
}
mergeNavigationOptions(componentId, options);
}
export function isThemeSwitchingEnabled(state) {
const {config} = state.entities.general;
return config.EnableThemeSelection === 'true';
}
export function getKeyboardAppearanceFromTheme(theme) {
return tinyColor(theme.centerChannelBg).isLight() ? 'light' : 'dark';
}
export function hexToHue(hexColor) {
let {red, green, blue} = ThemeUtils.getComponents(hexColor);
red /= 255;
green /= 255;
blue /= 255;
const channelMax = Math.max(red, green, blue);
const channelMin = Math.min(red, green, blue);
const delta = channelMax - channelMin;
let hue = 0;
if (delta === 0) {
hue = 0;
} else if (channelMax === red) {
hue = ((green - blue) / delta) % 6;
} else if (channelMax === green) {
hue = ((blue - red) / delta) + 2;
} else {
hue = ((red - green) / delta) + 4;
}
hue = Math.round(hue * 60);
if (hue < 0) {
hue += 360;
}
return hue;
}