From f613cf122a0c224adbdc887e2a27f50946298438 Mon Sep 17 00:00:00 2001 From: Wesley Aptekar-Cassels Date: Fri, 28 May 2021 15:16:07 -0700 Subject: [PATCH 1/5] openLink [nfc]: Add jsdocs. --- src/utils/openLink.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/utils/openLink.js b/src/utils/openLink.js index 544ab09a93b..7836361ba2c 100644 --- a/src/utils/openLink.js +++ b/src/utils/openLink.js @@ -5,6 +5,7 @@ import SafariView from 'react-native-safari-view'; import type { BrowserPreference, GetState } from '../types'; import { getSettings } from '../selectors'; +/** Open a URL in the in-app browser. */ export function openLinkEmbedded(url: string): void { if (Platform.OS === 'ios') { SafariView.show({ url: encodeURI(url) }); @@ -13,6 +14,7 @@ export function openLinkEmbedded(url: string): void { } } +/** Open a URL in the user's default browser app. */ export function openLinkExternal(url: string): void { Linking.openURL(url); } @@ -27,6 +29,7 @@ export function shouldUseInAppBrowser(browser: BrowserPreference): boolean { // TODO: We may want to turn this into a thunk action creator. // See https://github.com/zulip/zulip-mobile/pull/4679#discussion_r625991786 +/** Open a URL using whichever browser the user has configured in the Zulip settings. */ export function openLinkWithUserPreference(url: string, getState: GetState): void { const state = getState(); const browser = getSettings(state).browser; From 82d6c155fcb343492b55a64ce4fc4066fcc49928 Mon Sep 17 00:00:00 2001 From: Wesley Aptekar-Cassels Date: Fri, 28 May 2021 15:24:53 -0700 Subject: [PATCH 2/5] openLink [nfc]: Take SettingsState instead of GetState. --- src/common/ServerCompatBanner.js | 6 +++--- src/message/messagesActions.js | 4 ++-- src/utils/openLink.js | 11 +++-------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/common/ServerCompatBanner.js b/src/common/ServerCompatBanner.js index 37ab067ab72..724785f560a 100644 --- a/src/common/ServerCompatBanner.js +++ b/src/common/ServerCompatBanner.js @@ -4,12 +4,11 @@ import React from 'react'; import { View } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; -import store from '../boot/store'; import { createStyleSheet, HALF_COLOR } from '../styles'; import { useSelector, useDispatch } from '../react-redux'; import Label from './Label'; import { getActiveAccount } from '../account/accountsSelectors'; -import { getIsAdmin, getSession } from '../directSelectors'; +import { getIsAdmin, getSession, getSettings } from '../directSelectors'; import { dismissCompatNotice } from '../session/sessionActions'; import ZulipTextButton from './ZulipTextButton'; import { openLinkWithUserPreference } from '../utils/openLink'; @@ -58,6 +57,7 @@ export default function ServerCompatBanner(props: Props) { const zulipVersion = useSelector(state => getActiveAccount(state).zulipVersion); const realm = useSelector(state => getActiveAccount(state).realm); const isAdmin = useSelector(getIsAdmin); + const settings = useSelector(getSettings); if (!zulipVersion || zulipVersion.isAtLeast(minSupportedVersion)) { return null; @@ -98,7 +98,7 @@ export default function ServerCompatBanner(props: Props) { onPress={() => { openLinkWithUserPreference( 'https://zulip.readthedocs.io/en/stable/overview/release-lifecycle.html#compatibility-and-upgrading', - store.getState, + settings, ); }} /> diff --git a/src/message/messagesActions.js b/src/message/messagesActions.js index 7daaf5f0783..a9999badf28 100644 --- a/src/message/messagesActions.js +++ b/src/message/messagesActions.js @@ -35,10 +35,10 @@ export const messageLinkPress = (href: string) => async ( const anchor = getMessageIdFromLink(href, auth.realm); dispatch(doNarrow(narrow, anchor)); } else if (!isUrlOnRealm(href, auth.realm)) { - openLinkWithUserPreference(href, getState); + openLinkWithUserPreference(href, state.settings); } else { const url = (await api.tryGetFileTemporaryUrl(href, auth)) ?? new URL(href, auth.realm).toString(); - openLinkWithUserPreference(url, getState); + openLinkWithUserPreference(url, state.settings); } }; diff --git a/src/utils/openLink.js b/src/utils/openLink.js index 7836361ba2c..1d51b1fe8d5 100644 --- a/src/utils/openLink.js +++ b/src/utils/openLink.js @@ -2,8 +2,7 @@ import { NativeModules, Platform, Linking } from 'react-native'; import SafariView from 'react-native-safari-view'; -import type { BrowserPreference, GetState } from '../types'; -import { getSettings } from '../selectors'; +import type { BrowserPreference, SettingsState } from '../types'; /** Open a URL in the in-app browser. */ export function openLinkEmbedded(url: string): void { @@ -27,13 +26,9 @@ export function shouldUseInAppBrowser(browser: BrowserPreference): boolean { } } -// TODO: We may want to turn this into a thunk action creator. -// See https://github.com/zulip/zulip-mobile/pull/4679#discussion_r625991786 /** Open a URL using whichever browser the user has configured in the Zulip settings. */ -export function openLinkWithUserPreference(url: string, getState: GetState): void { - const state = getState(); - const browser = getSettings(state).browser; - if (shouldUseInAppBrowser(browser)) { +export function openLinkWithUserPreference(url: string, settings: SettingsState): void { + if (shouldUseInAppBrowser(settings.browser)) { openLinkEmbedded(url); } else { openLinkExternal(url); From f5b05aed7aafe948eb856d77788b12b0a3cb6028 Mon Sep 17 00:00:00 2001 From: Wesley Aptekar-Cassels Date: Fri, 28 May 2021 15:33:36 -0700 Subject: [PATCH 3/5] OptionRow: Make height the same regardless of icon. This makes the OptionRow always the same height, regardless of whether there's an icon or not. As far as I can tell, this doesn't change any of the current uses of OptionRow (since almost all of them currently use icons). The value of 56 was discovered by inspecting OptionRows with icons - since RNVI uses font-size instead of width/height, there isn't a nice way to get the height of an icon from its size. This is in preparation for removing some icons from the settings screen. --- src/common/OptionRow.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/common/OptionRow.js b/src/common/OptionRow.js index 3f14b5a0453..b76d8b086a8 100644 --- a/src/common/OptionRow.js +++ b/src/common/OptionRow.js @@ -23,13 +23,16 @@ export default class OptionRow extends PureComponent { styles = { icon: styles.settingsIcon, + container: { + height: 56, + }, }; render() { const { label, value, onValueChange, style, Icon } = this.props; return ( - + {!!Icon && }