Skip to content

Commit 7471f6e

Browse files
committed
NotificationsScreen: Offer link to system notification settings for Zulip
1 parent d7a1f24 commit 7471f6e

File tree

8 files changed

+101
-1
lines changed

8 files changed

+101
-1
lines changed

ios/ZulipMobile/ZLPConstants.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ class ZLPConstants: NSObject {
1515

1616
@objc
1717
func constantsToExport() -> [String: Any]! {
18-
return ["resourceURL": Bundle.main.resourceURL!.absoluteString]
18+
var result: [String: Any] = [:]
19+
result["resourceURL"] = Bundle.main.resourceURL!.absoluteString
20+
result["UIApplication.openSettingsURLString"] = UIApplication.openSettingsURLString
21+
if #available(iOS 16.0, *) {
22+
// New name for the notification-settings URL
23+
// https://developer.apple.com/documentation/uikit/uiapplication/4013180-opennotificationsettingsurlstrin/
24+
// TODO(ios-16.0): Remove conditional and fallback for 15.4+.
25+
result["UIApplication.openNotificationSettingsURLString"] = UIApplication.openNotificationSettingsURLString
26+
}
27+
if #available(iOS 15.4, *) {
28+
// Old name for the notification-settings URL
29+
// https://developer.apple.com/documentation/uikit/uiapplicationopennotificationsettingsurlstring
30+
// TODO(ios-15.4): Remove conditional.
31+
result["UIApplicationOpenNotificationSettingsURLString"] = UIApplicationOpenNotificationSettingsURLString
32+
}
33+
return result
1934
}
2035
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"react-native-document-picker": "^3.2.4",
6161
"react-native-gesture-handler": "^2.8.0",
6262
"react-native-image-picker": "4.10.2",
63+
"react-native-open-notification": "^0.1.4",
6364
"react-native-photo-view": "alwx/react-native-photo-view#91b873c85",
6465
"react-native-reanimated": "^2.2.0 <2.3.0",
6566
"react-native-safe-area-context": "^4.3.1",

src/settings/NotificationsScreen.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import React, { useCallback } from 'react';
44
import type { Node } from 'react';
5+
import { Platform, Linking, NativeModules } from 'react-native';
6+
import OpenNotification from 'react-native-open-notification';
57

68
import type { RouteProp } from '../react-navigation';
79
import type { AppNavigationProp } from '../nav/AppNavigator';
@@ -11,19 +13,50 @@ import SwitchRow from '../common/SwitchRow';
1113
import Screen from '../common/Screen';
1214
import * as api from '../api';
1315
import ServerPushSetupBanner from '../common/ServerPushSetupBanner';
16+
import NestedNavRow from '../common/NestedNavRow';
17+
18+
const { ZLPConstants } = NativeModules;
1419

1520
type Props = $ReadOnly<{|
1621
navigation: AppNavigationProp<'notifications'>,
1722
route: RouteProp<'notifications', void>,
1823
|}>;
1924

25+
function openSystemNotificationSettings() {
26+
if (Platform.OS === 'ios') {
27+
Linking.openURL(
28+
// Link directly to notification settings when iOS supports it
29+
// (15.4+). Otherwise, link to the regular settings, and the user
30+
// should get to notification settings with one tap from there.
31+
ZLPConstants['UIApplication.openNotificationSettingsURLString'] // New name, iOS 16.0+
32+
// TODO(ios-16.0): Remove use of old name
33+
?? ZLPConstants.UIApplicationOpenNotificationSettingsURLString // Old name, iOS 15.4+
34+
// TODO(ios-15.4): Remove fallback.
35+
?? ZLPConstants['UIApplication.openSettingsURLString'],
36+
);
37+
} else {
38+
// On iOS, react-native-open-notification doesn't support opening all
39+
// the way to *notification* settings. It does support that on
40+
// Android, so we use it here. The library is oddly named for one that
41+
// opens notification settings; perhaps one day we'll replace it with
42+
// our own code. But Greg points out that the implementation is small
43+
// and reasonable:
44+
// https://github.com/zulip/zulip-mobile/pull/5627#discussion_r1058039648
45+
OpenNotification.open();
46+
}
47+
}
48+
2049
/** (NB this is a per-account screen -- these are per-account settings.) */
2150
export default function NotificationsScreen(props: Props): Node {
2251
const auth = useSelector(getAuth);
2352
const offlineNotification = useSelector(state => getSettings(state).offlineNotification);
2453
const onlineNotification = useSelector(state => getSettings(state).onlineNotification);
2554
const streamNotification = useSelector(state => getSettings(state).streamNotification);
2655

56+
const handleSystemSettingsPress = useCallback(() => {
57+
openSystemNotificationSettings();
58+
}, []);
59+
2760
// TODO(#3999): It'd be good to show "working on it" UI feedback while a
2861
// request is pending, after the user touches a switch.
2962

@@ -54,6 +87,7 @@ export default function NotificationsScreen(props: Props): Node {
5487
return (
5588
<Screen title="Notifications">
5689
<ServerPushSetupBanner isDismissable={false} />
90+
<NestedNavRow label="System settings for Zulip" onPress={handleSystemSettingsPress} />
5791
<SwitchRow
5892
label="Notifications when offline"
5993
value={offlineNotification}

static/translations/messages_en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@
223223
"Forgot password?": "Forgot password?",
224224
"Recipients": "Recipients",
225225
"Delete message": "Delete message",
226+
"System settings for Zulip": "System settings for Zulip",
226227
"Notifications when online": "Notifications when online",
227228
"Notifications when offline": "Notifications when offline",
228229
"Stream notifications": "Stream notifications",

tools/tsflower

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ run_only()
147147
# TODO get list of packages from data... better yet, make it
148148
# one tsflower command, reading a TsFlower config file
149149

150+
package=react-native-open-notification
151+
run_on_package "${package}"
152+
format_dir "${rootdir}"/types/"${package}"
153+
150154
package=expo-application
151155
run_on_package "${package}"
152156
format_dir "${rootdir}"/types/"${package}"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Chris Bobbe <[email protected]>
3+
Date: Thu, 22 Dec 2022 12:03:43 -0500
4+
Subject: [tsflower] r-n-open-notification: Translate a ModuleDeclaration
5+
6+
---
7+
types/react-native-open-notification/index.js.flow | 12 +++++-------
8+
1 file changed, 5 insertions(+), 7 deletions(-)
9+
10+
diff --git types/react-native-open-notification/index.js.flow types/react-native-open-notification/index.js.flow
11+
index 209d470f6..7782c030c 100644
12+
--- types/react-native-open-notification/index.js.flow
13+
+++ types/react-native-open-notification/index.js.flow
14+
@@ -1,10 +1,8 @@
15+
/* @flow
16+
* @generated by TsFlower
17+
*/
18+
-/* tsflower-unimplemented: ModuleDeclaration */
19+
-/* declare module 'react-native-open-notification' {
20+
- class NotificationSetting {
21+
- static open: () => void;
22+
- }
23+
- export default NotificationSetting;
24+
-} */
25+
+
26+
+class NotificationSetting {
27+
+ static open: () => void;
28+
+}
29+
+export default NotificationSetting;
30+
--
31+
2.32.0
32+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* @flow
2+
* @generated by TsFlower
3+
*/
4+
5+
class NotificationSetting {
6+
static open: () => void;
7+
}
8+
export default NotificationSetting;

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10232,6 +10232,11 @@ react-native-iphone-x-helper@^1.3.0:
1023210232
resolved "https://registry.yarnpkg.com/react-native-iphone-x-helper/-/react-native-iphone-x-helper-1.3.1.tgz#20c603e9a0e765fd6f97396638bdeb0e5a60b010"
1023310233
integrity sha512-HOf0jzRnq2/aFUcdCJ9w9JGzN3gdEg0zFE4FyYlp4jtidqU03D5X7ZegGKfT1EWteR0gPBGp9ye5T5FvSWi9Yg==
1023410234

10235+
react-native-open-notification@^0.1.4:
10236+
version "0.1.4"
10237+
resolved "https://registry.yarnpkg.com/react-native-open-notification/-/react-native-open-notification-0.1.4.tgz#20b7c03a1543ce36f3f99ff9924c67eef2688aa9"
10238+
integrity sha512-TPeFRsao6nDFW5nvBseD6nheRCN1U3poaY90iDzBY1MEEVepClqfEC9Iw0cqj7LYnpDSF8V25fb/SpjEg3HdQQ==
10239+
1023510240
react-native-photo-view@alwx/react-native-photo-view#91b873c85:
1023610241
version "1.5.3"
1023710242
resolved "https://codeload.github.com/alwx/react-native-photo-view/tar.gz/91b873c85c5c48af41b93cf6bf34e0a40502f754"

0 commit comments

Comments
 (0)