livevoice-sdk-react-native 2.0.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/README.md +105 -66
  2. package/android/build.gradle +5 -4
  3. package/android/src/main/java/io/livevoice/react/LiveVoiceModule.kt +122 -188
  4. package/android/src/main/java/io/livevoice/react/__SDK.kt +2 -2
  5. package/ios/LiveVoiceRNBridge.swift +362 -0
  6. package/ios/LiveVoiceSdkReactNative.mm +187 -158
  7. package/ios/__SDK.h +1 -1
  8. package/ios/livevoice_spm_backport.rb +202 -0
  9. package/lib/module/components/BrandingView.js +58 -39
  10. package/lib/module/components/BrandingView.js.map +1 -1
  11. package/lib/module/components/ChannelView.js +355 -44
  12. package/lib/module/components/ChannelView.js.map +1 -1
  13. package/lib/module/components/ErrorView.js +5 -6
  14. package/lib/module/components/ErrorView.js.map +1 -1
  15. package/lib/module/components/LiveVoiceSpinner.js +81 -0
  16. package/lib/module/components/LiveVoiceSpinner.js.map +1 -0
  17. package/lib/module/components/LiveVoiceView.js +311 -133
  18. package/lib/module/components/LiveVoiceView.js.map +1 -1
  19. package/lib/module/components/PasswordPrompt.js +165 -0
  20. package/lib/module/components/PasswordPrompt.js.map +1 -0
  21. package/lib/module/components/PlayButtonView.js +180 -244
  22. package/lib/module/components/PlayButtonView.js.map +1 -1
  23. package/lib/module/components/ReconnectingView.js +31 -53
  24. package/lib/module/components/ReconnectingView.js.map +1 -1
  25. package/lib/module/icons/branding-ios.png +0 -0
  26. package/lib/module/icons/camera-off-android.png +0 -0
  27. package/lib/module/icons/camera-off-android@2x.png +0 -0
  28. package/lib/module/icons/camera-off-android@3x.png +0 -0
  29. package/lib/module/icons/cpu-android.png +0 -0
  30. package/lib/module/icons/cpu-android@2x.png +0 -0
  31. package/lib/module/icons/cpu-android@3x.png +0 -0
  32. package/lib/module/icons/cpu-ios.png +0 -0
  33. package/lib/module/icons/cpu-ios@2x.png +0 -0
  34. package/lib/module/icons/cpu-ios@3x.png +0 -0
  35. package/lib/module/icons/lock-android.png +0 -0
  36. package/lib/module/icons/lock-android@2x.png +0 -0
  37. package/lib/module/icons/lock-android@3x.png +0 -0
  38. package/lib/module/icons/lock-ios.png +0 -0
  39. package/lib/module/icons/lock-ios@2x.png +0 -0
  40. package/lib/module/icons/lock-ios@3x.png +0 -0
  41. package/lib/module/icons/mic-off-android.png +0 -0
  42. package/lib/module/icons/mic-off-android@2x.png +0 -0
  43. package/lib/module/icons/mic-off-android@3x.png +0 -0
  44. package/lib/module/icons/mic-slash-ios.png +0 -0
  45. package/lib/module/icons/mic-slash-ios@2x.png +0 -0
  46. package/lib/module/icons/mic-slash-ios@3x.png +0 -0
  47. package/lib/module/icons/video-slash-ios.png +0 -0
  48. package/lib/module/icons/video-slash-ios@2x.png +0 -0
  49. package/lib/module/icons/video-slash-ios@3x.png +0 -0
  50. package/lib/module/index.js +11 -6
  51. package/lib/module/index.js.map +1 -1
  52. package/lib/module/sdk/Bridge.js +236 -0
  53. package/lib/module/sdk/Bridge.js.map +1 -0
  54. package/lib/module/sdk/Event.js +160 -0
  55. package/lib/module/sdk/Event.js.map +1 -0
  56. package/lib/module/sdk/Lifecycle.js +331 -0
  57. package/lib/module/sdk/Lifecycle.js.map +1 -0
  58. package/lib/module/sdk/LiveVoiceSdk.js +262 -268
  59. package/lib/module/sdk/LiveVoiceSdk.js.map +1 -1
  60. package/lib/module/sdk/LiveVoiceState.js +208 -40
  61. package/lib/module/sdk/LiveVoiceState.js.map +1 -1
  62. package/lib/module/sdk/LogEntries.js +99 -0
  63. package/lib/module/sdk/LogEntries.js.map +1 -0
  64. package/lib/module/sdk/Models.js +2 -0
  65. package/lib/module/{util/UIState.js.map → sdk/Models.js.map} +1 -1
  66. package/lib/module/{util/PlayingState.js → sdk/NativeSdkVersions.js} +9 -8
  67. package/lib/module/sdk/NativeSdkVersions.js.map +1 -0
  68. package/lib/module/sdk/Observables.js +391 -0
  69. package/lib/module/sdk/Observables.js.map +1 -0
  70. package/lib/module/sdk/Passwords.js +298 -0
  71. package/lib/module/sdk/Passwords.js.map +1 -0
  72. package/lib/module/sdk/Playback.js +35 -0
  73. package/lib/module/sdk/Playback.js.map +1 -0
  74. package/lib/module/specs/NativeLiveVoiceSdk.js.map +1 -1
  75. package/lib/module/util/Colors.js +2 -1
  76. package/lib/module/util/Colors.js.map +1 -1
  77. package/lib/module/util/Translations.js +34 -11
  78. package/lib/module/util/Translations.js.map +1 -1
  79. package/lib/module/util/freeze.js +26 -0
  80. package/lib/module/util/freeze.js.map +1 -0
  81. package/lib/module/util/logger.js +79 -41
  82. package/lib/module/util/logger.js.map +1 -1
  83. package/lib/typescript/src/components/BrandingView.d.ts +4 -0
  84. package/lib/typescript/src/components/BrandingView.d.ts.map +1 -1
  85. package/lib/typescript/src/components/ChannelView.d.ts +29 -3
  86. package/lib/typescript/src/components/ChannelView.d.ts.map +1 -1
  87. package/lib/typescript/src/components/ErrorView.d.ts +5 -3
  88. package/lib/typescript/src/components/ErrorView.d.ts.map +1 -1
  89. package/lib/typescript/src/components/LiveVoiceSpinner.d.ts +16 -0
  90. package/lib/typescript/src/components/LiveVoiceSpinner.d.ts.map +1 -0
  91. package/lib/typescript/src/components/LiveVoiceView.d.ts +81 -21
  92. package/lib/typescript/src/components/LiveVoiceView.d.ts.map +1 -1
  93. package/lib/typescript/src/components/PasswordPrompt.d.ts +13 -0
  94. package/lib/typescript/src/components/PasswordPrompt.d.ts.map +1 -0
  95. package/lib/typescript/src/components/PlayButtonView.d.ts +12 -329
  96. package/lib/typescript/src/components/PlayButtonView.d.ts.map +1 -1
  97. package/lib/typescript/src/components/ReconnectingView.d.ts +6 -3
  98. package/lib/typescript/src/components/ReconnectingView.d.ts.map +1 -1
  99. package/lib/typescript/src/index.d.ts +15 -6
  100. package/lib/typescript/src/index.d.ts.map +1 -1
  101. package/lib/typescript/src/sdk/Bridge.d.ts +36 -0
  102. package/lib/typescript/src/sdk/Bridge.d.ts.map +1 -0
  103. package/lib/typescript/src/sdk/Event.d.ts +97 -0
  104. package/lib/typescript/src/sdk/Event.d.ts.map +1 -0
  105. package/lib/typescript/src/sdk/Lifecycle.d.ts +191 -0
  106. package/lib/typescript/src/sdk/Lifecycle.d.ts.map +1 -0
  107. package/lib/typescript/src/sdk/LiveVoiceSdk.d.ts +195 -190
  108. package/lib/typescript/src/sdk/LiveVoiceSdk.d.ts.map +1 -1
  109. package/lib/typescript/src/sdk/LiveVoiceState.d.ts +77 -9
  110. package/lib/typescript/src/sdk/LiveVoiceState.d.ts.map +1 -1
  111. package/lib/typescript/src/sdk/LogEntries.d.ts +28 -0
  112. package/lib/typescript/src/sdk/LogEntries.d.ts.map +1 -0
  113. package/lib/typescript/src/sdk/Models.d.ts +114 -0
  114. package/lib/typescript/src/sdk/Models.d.ts.map +1 -0
  115. package/lib/typescript/src/sdk/NativeSdkVersions.d.ts +6 -0
  116. package/lib/typescript/src/sdk/NativeSdkVersions.d.ts.map +1 -0
  117. package/lib/typescript/src/sdk/Observables.d.ts +123 -0
  118. package/lib/typescript/src/sdk/Observables.d.ts.map +1 -0
  119. package/lib/typescript/src/sdk/Passwords.d.ts +72 -0
  120. package/lib/typescript/src/sdk/Passwords.d.ts.map +1 -0
  121. package/lib/typescript/src/sdk/Playback.d.ts +9 -0
  122. package/lib/typescript/src/sdk/Playback.d.ts.map +1 -0
  123. package/lib/typescript/src/specs/NativeLiveVoiceSdk.d.ts +34 -31
  124. package/lib/typescript/src/specs/NativeLiveVoiceSdk.d.ts.map +1 -1
  125. package/lib/typescript/src/util/Colors.d.ts.map +1 -1
  126. package/lib/typescript/src/util/Translations.d.ts +30 -8
  127. package/lib/typescript/src/util/Translations.d.ts.map +1 -1
  128. package/lib/typescript/src/util/freeze.d.ts +6 -0
  129. package/lib/typescript/src/util/freeze.d.ts.map +1 -0
  130. package/lib/typescript/src/util/logger.d.ts +17 -7
  131. package/lib/typescript/src/util/logger.d.ts.map +1 -1
  132. package/livevoice-sdk-react-native.podspec +29 -4
  133. package/package.json +12 -9
  134. package/src/components/BrandingView.tsx +42 -55
  135. package/src/components/ChannelView.tsx +329 -38
  136. package/src/components/ErrorView.tsx +9 -12
  137. package/src/components/LiveVoiceSpinner.tsx +87 -0
  138. package/src/components/LiveVoiceView.tsx +319 -201
  139. package/src/components/PasswordPrompt.tsx +144 -0
  140. package/src/components/PlayButtonView.tsx +165 -269
  141. package/src/components/ReconnectingView.tsx +28 -81
  142. package/src/icons/branding-ios.png +0 -0
  143. package/src/icons/camera-off-android.png +0 -0
  144. package/src/icons/camera-off-android@2x.png +0 -0
  145. package/src/icons/camera-off-android@3x.png +0 -0
  146. package/src/icons/cpu-android.png +0 -0
  147. package/src/icons/cpu-android@2x.png +0 -0
  148. package/src/icons/cpu-android@3x.png +0 -0
  149. package/src/icons/cpu-ios.png +0 -0
  150. package/src/icons/cpu-ios@2x.png +0 -0
  151. package/src/icons/cpu-ios@3x.png +0 -0
  152. package/src/icons/lock-android.png +0 -0
  153. package/src/icons/lock-android@2x.png +0 -0
  154. package/src/icons/lock-android@3x.png +0 -0
  155. package/src/icons/lock-ios.png +0 -0
  156. package/src/icons/lock-ios@2x.png +0 -0
  157. package/src/icons/lock-ios@3x.png +0 -0
  158. package/src/icons/mic-off-android.png +0 -0
  159. package/src/icons/mic-off-android@2x.png +0 -0
  160. package/src/icons/mic-off-android@3x.png +0 -0
  161. package/src/icons/mic-slash-ios.png +0 -0
  162. package/src/icons/mic-slash-ios@2x.png +0 -0
  163. package/src/icons/mic-slash-ios@3x.png +0 -0
  164. package/src/icons/video-slash-ios.png +0 -0
  165. package/src/icons/video-slash-ios@2x.png +0 -0
  166. package/src/icons/video-slash-ios@3x.png +0 -0
  167. package/src/index.tsx +92 -6
  168. package/src/sdk/Bridge.ts +259 -0
  169. package/src/sdk/Event.ts +187 -0
  170. package/src/sdk/Lifecycle.ts +366 -0
  171. package/src/sdk/LiveVoiceSdk.ts +285 -309
  172. package/src/sdk/LiveVoiceState.ts +230 -60
  173. package/src/sdk/LogEntries.ts +88 -0
  174. package/src/sdk/Models.ts +129 -0
  175. package/src/{util/PlayingState.ts → sdk/NativeSdkVersions.ts} +7 -6
  176. package/src/sdk/Observables.ts +414 -0
  177. package/src/sdk/Passwords.ts +286 -0
  178. package/src/sdk/Playback.ts +30 -0
  179. package/src/specs/NativeLiveVoiceSdk.ts +42 -38
  180. package/src/util/Colors.ts +2 -1
  181. package/src/util/Translations.ts +34 -12
  182. package/src/util/freeze.ts +23 -0
  183. package/src/util/logger.ts +79 -52
  184. package/lib/module/components/AudioOutputSwitchView.js +0 -138
  185. package/lib/module/components/AudioOutputSwitchView.js.map +0 -1
  186. package/lib/module/components/index.js +0 -24
  187. package/lib/module/components/index.js.map +0 -1
  188. package/lib/module/icons/mic.png +0 -0
  189. package/lib/module/util/ForegroundServiceConfig.js +0 -38
  190. package/lib/module/util/ForegroundServiceConfig.js.map +0 -1
  191. package/lib/module/util/PlayingState.js.map +0 -1
  192. package/lib/module/util/UIState.js +0 -4
  193. package/lib/typescript/src/components/AudioOutputSwitchView.d.ts +0 -6
  194. package/lib/typescript/src/components/AudioOutputSwitchView.d.ts.map +0 -1
  195. package/lib/typescript/src/components/index.d.ts +0 -9
  196. package/lib/typescript/src/components/index.d.ts.map +0 -1
  197. package/lib/typescript/src/util/ForegroundServiceConfig.d.ts +0 -19
  198. package/lib/typescript/src/util/ForegroundServiceConfig.d.ts.map +0 -1
  199. package/lib/typescript/src/util/PlayingState.d.ts +0 -7
  200. package/lib/typescript/src/util/PlayingState.d.ts.map +0 -1
  201. package/lib/typescript/src/util/UIState.d.ts +0 -86
  202. package/lib/typescript/src/util/UIState.d.ts.map +0 -1
  203. package/src/components/AudioOutputSwitchView.tsx +0 -146
  204. package/src/components/index.tsx +0 -21
  205. package/src/icons/mic.png +0 -0
  206. package/src/util/ForegroundServiceConfig.tsx +0 -42
  207. package/src/util/UIState.ts +0 -106
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "livevoice-sdk-react-native",
3
- "version": "2.0.1",
3
+ "version": "3.0.0",
4
4
  "description": "The LiveVoice SDK for integrating simultaneous interpretation, AI voice translation, guided tours, silent events, and more into your app.",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -13,13 +13,13 @@
13
13
  "./package.json": "./package.json"
14
14
  },
15
15
  "files": [
16
- "src",
17
- "lib",
18
- "android",
19
- "ios",
20
- "cpp",
21
- "*.podspec",
22
- "react-native.config.js",
16
+ "./src",
17
+ "./lib",
18
+ "./android",
19
+ "./ios",
20
+ "./cpp",
21
+ "./livevoice-sdk-react-native.podspec",
22
+ "./react-native.config.js",
23
23
  "!ios/build",
24
24
  "!ios/generated",
25
25
  "!android/generated",
@@ -37,6 +37,7 @@
37
37
  "example": "yarn workspace livevoice-sdk-react-native-example",
38
38
  "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
39
39
  "prepare": "bob build",
40
+ "prepublishOnly": "node tool/check-publish.mjs",
40
41
  "test": "jest --runInBand",
41
42
  "typecheck": "tsc",
42
43
  "check:headers": "node tool/license-headers.mjs --check",
@@ -46,10 +47,12 @@
46
47
  "headers:fix": "node tool/license-headers.mjs --fix",
47
48
  "native-version-generate": "node tool/generate-native-versions.mjs",
48
49
  "versions:sync": "node tool/generate-native-versions.mjs",
50
+ "test:matrix-tool": "node --test tool/tests/*.test.mjs",
49
51
  "matrix:list": "node tool/test-rn-version.mjs --list-versions-json",
50
52
  "matrix:test": "node tool/test-rn-version.mjs",
51
53
  "clear-all": "node tool/clean-all.mjs",
52
- "clean:all": "node tool/clean-all.mjs"
54
+ "clean:all": "node tool/clean-all.mjs",
55
+ "typecheck:example": "tsc -p example/tsconfig.json"
53
56
  },
54
57
  "keywords": [
55
58
  "react-native",
@@ -12,72 +12,59 @@
12
12
  //===----------------------------------------------------------------------===//
13
13
 
14
14
  import React from 'react';
15
- import {
16
- View,
17
- Text,
18
- useColorScheme,
19
- StyleSheet,
20
- Image,
21
- Pressable
22
- } from 'react-native';
15
+ import { Image, Platform, Pressable, StyleSheet, Text, useColorScheme } from 'react-native';
23
16
 
24
- import { COLORS } from '../util/Colors';
25
17
  import { openLiveVoiceWebsite } from '../sdk/LiveVoiceSdk';
18
+ import { Translations } from '../util/Translations';
26
19
 
27
20
  export interface BrandingProps {
28
21
  isDarkMode?: boolean;
29
22
  }
30
23
 
24
+ /**
25
+ * The "Live Audio Streaming by LiveVoice" footer, drawn exactly as the native SDK of the platform
26
+ * draws it: iOS `LogoView`, Android `LiveVoiceSdkBranding`. Change them together.
27
+ */
31
28
  export const BrandingView: React.FC<BrandingProps> = (props) => {
32
- const isDarkMode = props.isDarkMode ?? useColorScheme() === 'dark';
33
-
34
- const openLink = async () => { openLiveVoiceWebsite(); }
29
+ const scheme = useColorScheme();
30
+ const isDarkMode = props.isDarkMode ?? scheme === 'dark';
31
+ // Both native footers draw the text and the logo in plain black or white.
32
+ const color = isDarkMode ? '#FFFFFF' : '#000000';
35
33
 
36
34
  return (
37
- <Pressable onPress={openLink} style={{ width: '100%', alignItems: 'center' }}>
38
- <View style={styles.container}>
39
- <Text style={[styles.text, isDarkMode ? styles.darkText : styles.lightText]}>
40
- Live Audio Streaming by
41
- </Text>
42
- <Image
43
- source={require('../icons/branding.png')}
44
- style={[
45
- styles.image,
46
- {
47
- height: 30,
48
- tintColor: isDarkMode ? COLORS.white : COLORS.black,
49
- },
50
- ]}
51
- resizeMode="contain"
52
- />
53
- </View>
35
+ <Pressable onPress={() => { openLiveVoiceWebsite(); }} style={styles.container}>
36
+ <Text style={[styles.text, { color }]} allowFontScaling={Platform.OS !== 'ios'}>
37
+ {Translations.streamingByTitle()}
38
+ </Text>
39
+ <Image
40
+ source={Platform.OS === 'ios' ? require('../icons/branding-ios.png') : require('../icons/branding.png')}
41
+ style={[styles.logo, { tintColor: color }]}
42
+ resizeMode="contain"
43
+ />
54
44
  </Pressable>
55
45
  );
56
46
  };
57
47
 
58
- const styles = StyleSheet.create({
59
- container: {
60
- padding: 12,
61
- alignItems: 'center',
62
- justifyContent: 'center',
63
- borderRadius: 8,
64
- width: 250,
65
- },
66
- text: {
67
- textAlign: 'center',
68
- fontSize: 16,
69
- fontWeight: '500',
70
- marginBottom: 4,
71
- },
72
- darkText: {
73
- color: '#fff',
74
- },
75
- lightText: {
76
- color: '#191919',
77
- },
78
- image: {
79
- width: '100%',
80
- height: undefined,
81
- aspectRatio: 4,
82
- },
83
- });
48
+ const styles = StyleSheet.create(Platform.OS === 'ios'
49
+ ? {
50
+ // iOS: `.padding()` (16 pt) around a 4 pt stack of a fixed 12 pt medium text and the logo
51
+ // set 100 pt wide. The logo artwork keeps the margins of the SDK's SVG (196 × 48).
52
+ container: { alignSelf: 'center', alignItems: 'center', padding: 16 },
53
+ text: { textAlign: 'center', fontSize: 12, fontWeight: '500', marginBottom: 4 },
54
+ logo: { width: 100, height: (100 * 48) / 196 },
55
+ }
56
+ : {
57
+ // Android: 8 dp above (from the view), below and at the sides; bodyMedium text and a
58
+ // 92 × 28 dp logo, each inset 8 dp more at the sides.
59
+ container: { alignSelf: 'center', alignItems: 'center', paddingTop: 8, paddingBottom: 8, paddingHorizontal: 8 },
60
+ text: {
61
+ textAlign: 'center',
62
+ fontSize: 14,
63
+ lineHeight: 20,
64
+ letterSpacing: 0.25,
65
+ fontWeight: '400',
66
+ includeFontPadding: false,
67
+ marginHorizontal: 8,
68
+ },
69
+ logo: { width: 92, height: 28, marginHorizontal: 8 },
70
+ });
@@ -12,84 +12,375 @@
12
12
  //===----------------------------------------------------------------------===//
13
13
 
14
14
  import React, { useState } from 'react';
15
- import { View, Text, StyleSheet, TouchableOpacity, useColorScheme, Image } from 'react-native';
16
- import { COLORS } from '../util/Colors';
17
- import { type PlayingState } from '../util/PlayingState';
15
+ import {
16
+ View,
17
+ Text,
18
+ StyleSheet,
19
+ TouchableOpacity,
20
+ useColorScheme,
21
+ useWindowDimensions,
22
+ Image,
23
+ Platform,
24
+ type AccessibilityActionEvent,
25
+ type AccessibilityValue,
26
+ type TextStyle,
27
+ type ViewProps,
28
+ } from 'react-native';
29
+ import {
30
+ type CellAccessibility,
31
+ type CellActionKind,
32
+ type CellMuteMark,
33
+ type CellStatus,
34
+ } from '../sdk/LiveVoiceState';
35
+ import { type LiveVoicePlayingState } from '../sdk/Models';
18
36
  import PlayButtonView from './PlayButtonView';
19
37
 
20
38
 
21
39
  export interface ChannelProps {
22
40
  channelName: string;
23
- playingState: PlayingState;
24
- muted: boolean;
41
+ playingState: LiveVoicePlayingState;
25
42
  isOnline: boolean;
26
43
  hasAudio: boolean;
27
44
  hasSubtitles: boolean;
45
+ /** The status line under the name, as native computed it (bridge.md 2.4); `null` for none. */
46
+ status?: CellStatus | null;
47
+ /** The mute mark at the end of the row, as native computed it (bridge.md 2.4); `null` for none. */
48
+ muteMark?: CellMuteMark | null;
49
+ /** A password-protected channel: the lock at the end of the row. */
50
+ isPasswordProtected?: boolean;
28
51
  isDarkMode?: boolean;
52
+ /**
53
+ * Drawn at half strength while the connection briefly recovers. The audio tap still reaches
54
+ * the SDK, which decides; the subtitle tap does nothing meanwhile.
55
+ */
56
+ isDimmed?: boolean;
57
+ /** The event's brand colour for this appearance; LiveVoice orange when `null`. */
58
+ brandColor?: string | null;
59
+ /** Whether this channel's subtitles are the open ones: the play button marks its subtitle half. */
60
+ subtitlesOpen?: boolean;
61
+ /**
62
+ * The row's accessibility as native computed it (bridge.md 2.4). With it the row is one
63
+ * accessibility element that renders exactly this; without it the row has none, as before.
64
+ */
65
+ accessibility?: CellAccessibility | null;
29
66
  onAudioPress?: () => void;
30
67
  onSubtitlesPress?: () => void;
31
68
  }
32
69
 
70
+ /**
71
+ * The default channel cell, drawn as the native SDK of the platform draws its row (iOS
72
+ * `ChannelCellView` in the `.sdk` mode, Android `DefaultChannel`; change them together). Where
73
+ * the two natives differed in behaviour, both follow iOS: the status rule, the expanded name, the
74
+ * dimming during the reconnect grace.
75
+ */
33
76
  export const ChannelView: React.FC<ChannelProps> = ({
34
77
  channelName,
35
78
  playingState,
36
- muted,
37
79
  isOnline,
38
80
  hasAudio,
39
81
  hasSubtitles,
82
+ status = null,
83
+ muteMark = null,
84
+ isPasswordProtected = false,
40
85
  isDarkMode = useColorScheme() === 'dark',
86
+ isDimmed = false,
87
+ brandColor = null,
88
+ subtitlesOpen = false,
89
+ accessibility = null,
41
90
  onAudioPress,
42
91
  onSubtitlesPress,
43
92
  }) => {
44
93
 
45
- const [collapsed, setCollapsed] = useState(true);
94
+ const [isExpanded, setExpanded] = useState(false);
95
+ /** How many lines the whole name takes at the column's width. */
96
+ const [nameLines, setNameLines] = useState(1);
97
+ // As iOS: a tap opens a name that does not fit one line to at most 4, and the row then aligns
98
+ // to the top; one that fits stays as it is.
99
+ const isOpen = isExpanded && nameLines > 1;
46
100
 
47
- const iconColor = isDarkMode ? COLORS.white : COLORS.black
101
+ const look = cellLook(isDarkMode, useWindowDimensions().fontScale);
102
+
103
+ const onSubtitles = isDimmed ? () => {} : onSubtitlesPress;
104
+ // An accessibility action does what a tap on the matching half does.
105
+ const run = (kind: CellActionKind | null) => {
106
+ if (kind === 'toggleAudio') onAudioPress?.();
107
+ else if (kind === 'toggleSubtitles') onSubtitles?.();
108
+ };
48
109
 
49
110
  return (
50
- <View style={styles.container}>
51
- <PlayButtonView
52
- playingState={playingState}
53
- onAudioPress={onAudioPress}
54
- onSubtitlesPress={onSubtitlesPress}
55
- isDarkMode={isDarkMode}
56
- isChannelOnline={isOnline}
57
- hasAudio={hasAudio}
58
- hasSubtitles={hasSubtitles}
59
- />
111
+ <View {...(accessibility === null ? null : rowAccessibility(accessibility, run))}>
112
+ <View
113
+ style={[styles.container, { alignItems: isOpen ? 'flex-start' : 'center' }]}
114
+ {...(accessibility === null ? null : hiddenFromAccessibility)}
115
+ >
116
+ {/* Only the button dims during the reconnect grace. */}
117
+ <View style={[styles.button, { opacity: isDimmed ? 0.5 : 1 }]}>
118
+ <PlayButtonView
119
+ playingState={playingState}
120
+ onAudioPress={onAudioPress}
121
+ onSubtitlesPress={onSubtitles}
122
+ isDarkMode={isDarkMode}
123
+ isChannelOnline={isOnline}
124
+ hasAudio={hasAudio}
125
+ hasSubtitles={hasSubtitles}
126
+ brandColor={brandColor}
127
+ subtitlesOpen={subtitlesOpen}
128
+ />
129
+ </View>
60
130
 
61
- {/* Channel Name */}
62
- <View style={{ flex: 1, marginLeft: 10 }}>
63
- <TouchableOpacity onPress={() => setCollapsed(!collapsed)} activeOpacity={1}>
64
- <Text numberOfLines={collapsed ? 1 : undefined} ellipsizeMode='tail' style={[styles.text, { color: isDarkMode ? COLORS.white : COLORS.black }]}>
65
- {channelName}
66
- </Text>
131
+ <TouchableOpacity style={look.title} onPress={() => setExpanded(!isExpanded)} activeOpacity={1}>
132
+ <View>
133
+ <Text numberOfLines={isOpen ? 4 : 1} ellipsizeMode='tail' style={look.name}>
134
+ {channelName}
135
+ </Text>
136
+ {/* The whole name, unseen, to tell whether it fits one line. */}
137
+ <Text
138
+ style={[look.name, styles.measure]}
139
+ importantForAccessibility='no-hide-descendants'
140
+ accessibilityElementsHidden
141
+ onTextLayout={event => setNameLines(event.nativeEvent.lines.length)}
142
+ >
143
+ {channelName}
144
+ </Text>
145
+ </View>
146
+ {status !== null && (
147
+ <View style={look.statusRow}>
148
+ {status.showsAiIcon && (
149
+ <Image source={look.cpu.source} style={[look.cpu.style, { tintColor: look.status.color }]} />
150
+ )}
151
+ <Text numberOfLines={1} style={[look.status, status.showsAiIcon ? look.cpu.text : null]}>
152
+ {status.showsAiIcon ? look.cpu.before : ''}{status.text}
153
+ </Text>
154
+ </View>
155
+ )}
67
156
  </TouchableOpacity>
157
+ {look.spacer && <View style={styles.spacer} />}
158
+ {muteMark !== null && (
159
+ <View style={look.mute.frame}>
160
+ <Image source={look.mute[muteMark].source} style={look.mute[muteMark].style} />
161
+ </View>
162
+ )}
163
+ {isPasswordProtected && (
164
+ <View style={look.lock.frame}>
165
+ <Image source={look.lock.source} style={look.lock.style} />
166
+ </View>
167
+ )}
68
168
  </View>
69
- {
70
- muted &&
71
- <Image
72
- source={require('../icons/mic.png')}
73
- style={{ tintColor: iconColor, width: 20, height: 20, resizeMode: 'contain' }} />
74
- }
75
169
  </View>
76
170
  );
77
171
  };
78
172
 
173
+ /** The system grey of the mute mark and the lock: iOS `.gray`, Android `RawColors.systemGray`. */
174
+ const systemGray = '#8E8E93';
175
+
176
+ /**
177
+ * The row's type, colours and marks on this platform.
178
+ *
179
+ * - iOS (`ChannelCellView.swift`): the name `.headline` (17 pt semibold) in `.primary`; the status
180
+ * `.caption` (12 pt) in `.secondary`, `Text(Image("cpu")) + " " + Text(status)` for an AI
181
+ * speaker; the mute mark `mic.slash.fill` or `video.slash.fill` and the lock `lock.fill`, each at
182
+ * its natural size centred in a 30 pt frame, 12 apart and 12 after the flexible space (at least
183
+ * 8) that follows the name. The glyphs are UIKit's renders at `.body` and `.caption`, sized by
184
+ * their point sizes.
185
+ * - Android (`DefaultChannel.kt`, `ChannelNameAndStatus.kt`, `ChannelMuteIcon.kt`): the name
186
+ * `titleMedium` (16 sp, 500, line height 24, letter spacing 0.15) in `onBackground`; the status
187
+ * `bodySmall` (12 sp, line height 16, letter spacing 0.4) in `onBackgroundInactive`,
188
+ * `livevoice_ic_cpu` 16 dp and 4 dp before an AI speaker's; the mute mark
189
+ * `livevoice_ic_microphone_off` or `livevoice_ic_camera_off` 24 dp right after the name; the
190
+ * lock `livevoice_ic_lock` in a 30 dp frame with 5 dp padding, 12 dp after.
191
+ *
192
+ * `fontScale` is the system text size React Native applies to text; only the iOS `cpu` uses it, to
193
+ * keep its baseline on the text's.
194
+ */
195
+ function cellLook(isDarkMode: boolean, fontScale: number) {
196
+ if (Platform.OS === 'ios') {
197
+ // The `cpu` symbol in the caption line, as `Text(Image)`: its baseline, 2.33 above its bottom,
198
+ // on the text's, which lies the caption font's ascender (11.43 at 12 pt) below the line's top.
199
+ // Whichever of the two would start higher starts the row; the other moves down.
200
+ const cpuTop = 11.43 * fontScale - (40 / 3 - 7 / 3);
201
+ return {
202
+ name: { fontSize: 17, fontWeight: '600', color: isDarkMode ? '#FFFFFF' : '#000000' } as TextStyle,
203
+ status: {
204
+ fontSize: 12,
205
+ fontWeight: '400',
206
+ color: isDarkMode ? 'rgba(235, 235, 245, 0.6)' : 'rgba(60, 60, 67, 0.6)',
207
+ } as TextStyle,
208
+ statusRow: styles.statusIos,
209
+ cpu: {
210
+ source: require('../icons/cpu-ios.png'),
211
+ style: { width: 44 / 3, height: 40 / 3, marginTop: Math.max(0, cpuTop) },
212
+ text: { marginTop: Math.max(0, -cpuTop) },
213
+ // The space of `+ " " +`, in the caption font.
214
+ before: ' ',
215
+ },
216
+ // As wide as the name needs; the flexible space after it takes the rest.
217
+ title: styles.titleShrinks,
218
+ spacer: true,
219
+ mute: {
220
+ frame: styles.iosMark,
221
+ microphone: { source: require('../icons/mic-slash-ios.png'), style: { width: 17, height: 20, tintColor: systemGray } },
222
+ camera: { source: require('../icons/video-slash-ios.png'), style: { width: 25, height: 67 / 3, tintColor: systemGray } },
223
+ },
224
+ lock: {
225
+ frame: styles.iosMark,
226
+ source: require('../icons/lock-ios.png'),
227
+ style: { width: 16, height: 55 / 3, tintColor: systemGray },
228
+ },
229
+ };
230
+ }
231
+ return {
232
+ name: {
233
+ fontSize: 16,
234
+ fontWeight: '500',
235
+ lineHeight: 24,
236
+ letterSpacing: 0.15,
237
+ includeFontPadding: false,
238
+ color: isDarkMode ? '#FFFFFF' : '#191919',
239
+ } as TextStyle,
240
+ status: {
241
+ fontSize: 12,
242
+ fontWeight: '400',
243
+ lineHeight: 16,
244
+ letterSpacing: 0.4,
245
+ includeFontPadding: false,
246
+ color: isDarkMode ? '#8B9299' : '#6D757D',
247
+ } as TextStyle,
248
+ statusRow: styles.statusAndroid,
249
+ cpu: {
250
+ source: require('../icons/cpu-android.png'),
251
+ style: { width: 16, height: 16, marginRight: 4 },
252
+ text: null,
253
+ before: '',
254
+ },
255
+ // The rest of the row (`weight(1f)`), so the mute mark sits at its end.
256
+ title: styles.titleFills,
257
+ spacer: false,
258
+ mute: {
259
+ frame: styles.androidMute,
260
+ microphone: { source: require('../icons/mic-off-android.png'), style: { width: 24, height: 24, tintColor: systemGray } },
261
+ camera: { source: require('../icons/camera-off-android.png'), style: { width: 24, height: 24, tintColor: systemGray } },
262
+ },
263
+ lock: {
264
+ frame: styles.androidLock,
265
+ source: require('../icons/lock-android.png'),
266
+ style: { width: 20, height: 20, tintColor: systemGray },
267
+ },
268
+ };
269
+ }
270
+
271
+ /** The row's parts, which the row's own element speaks for. */
272
+ const hiddenFromAccessibility: ViewProps = {
273
+ importantForAccessibility: 'no-hide-descendants',
274
+ accessibilityElementsHidden: true,
275
+ };
276
+
277
+ /**
278
+ * React Native clears an Android view's whole content description, label included, when its
279
+ * `accessibilityValue` goes away, and keeps a stale value when one without `text` replaces it. An
280
+ * empty value is therefore a value whose `text` is `null`: no value on either platform.
281
+ */
282
+ const noValue = { text: null } as unknown as AccessibilityValue;
283
+
284
+ /**
285
+ * The row as one accessibility element, exactly as native computed it: its label, value, button
286
+ * role and selected state, what a double tap does, and the named actions in the native order.
287
+ *
288
+ * - iOS: VoiceOver's double tap is `onAccessibilityTap`, a no-op without an activation (the
289
+ * default would tap the row's middle). Every named action is a custom action, as the native row
290
+ * lists play or stop beside the double tap.
291
+ * - Android: TalkBack's double tap is the click, named after the activation's own action, as the
292
+ * native row's click label; TalkBack lists it with the actions, so the activation's entry
293
+ * becomes that click instead of a second action of the same name.
294
+ */
295
+ function rowAccessibility(accessibility: CellAccessibility, run: (kind: CellActionKind | null) => void): ViewProps {
296
+ const { activation } = accessibility;
297
+ const click = Platform.OS === 'android' && activation !== null
298
+ ? accessibility.actions.findIndex(action => action.kind === activation)
299
+ : -1;
300
+ const actions: Array<NonNullable<ViewProps['accessibilityActions']>[number]> = accessibility.actions.map((action, index) => ({
301
+ name: index === click ? 'activate' : action.kind,
302
+ label: action.name,
303
+ }));
304
+ if (Platform.OS === 'android' && activation !== null && click < 0) actions.unshift({ name: 'activate' });
305
+ return {
306
+ accessible: true,
307
+ accessibilityLabel: accessibility.label,
308
+ accessibilityValue: accessibility.value === '' ? noValue : { text: accessibility.value },
309
+ accessibilityRole: accessibility.isButton ? 'button' : undefined,
310
+ accessibilityState: { selected: accessibility.isSelected },
311
+ accessibilityActions: actions,
312
+ onAccessibilityTap: () => run(activation),
313
+ onAccessibilityAction: ({ nativeEvent: { actionName } }: AccessibilityActionEvent) => {
314
+ if (actionName === 'activate') run(activation);
315
+ else if (actionName === 'toggleAudio' || actionName === 'toggleSubtitles') run(actionName);
316
+ },
317
+ };
318
+ }
319
+
79
320
  const styles = StyleSheet.create({
321
+ // 12 at the sides (iOS `defaultCellInsets`, Android `padding(horizontal = 12.dp)`), 8 above and below.
80
322
  container: {
81
323
  flexDirection: 'row',
82
- alignItems: 'center',
83
324
  paddingHorizontal: 12,
84
325
  paddingVertical: 8,
85
326
  },
86
- text: {
87
- fontSize: 16,
88
- fontWeight: '500',
327
+ // 2 above and below the button, so a row is 64 tall, and 12 to the name.
328
+ button: {
329
+ paddingVertical: 2,
330
+ marginRight: 12,
331
+ },
332
+ // The name and the status line.
333
+ titleShrinks: {
334
+ flexShrink: 1,
335
+ },
336
+ // Android: the rest of the row, 20 clear of the marks as iOS's spacing of 12 and Spacer of 8.
337
+ titleFills: {
338
+ flex: 1,
339
+ marginRight: 20,
340
+ },
341
+ measure: {
342
+ position: 'absolute',
343
+ left: 0,
344
+ right: 0,
345
+ top: 0,
346
+ opacity: 0,
347
+ },
348
+ // iOS: the `cpu` placed on the text's baseline from the top; Android: centred, as its `Row`.
349
+ statusIos: {
350
+ flexDirection: 'row',
351
+ alignItems: 'flex-start',
352
+ marginTop: 2,
353
+ },
354
+ statusAndroid: {
355
+ flexDirection: 'row',
356
+ alignItems: 'center',
357
+ marginTop: 2,
358
+ },
359
+ // iOS's `Spacer()`: at least the default spacing of 8, 12 from the name beside it.
360
+ spacer: {
361
+ flexGrow: 1,
362
+ minWidth: 8,
363
+ marginLeft: 12,
364
+ },
365
+ iosMark: {
366
+ width: 30,
367
+ height: 30,
368
+ marginLeft: 12,
369
+ alignItems: 'center',
370
+ justifyContent: 'center',
371
+ },
372
+ // `ChannelMuteIcon`: the 24 dp glyph centred in a 30 dp frame, 12 after the name's gap.
373
+ androidMute: {
374
+ width: 30,
375
+ height: 30,
376
+ marginLeft: 12,
377
+ alignItems: 'center',
378
+ justifyContent: 'center',
89
379
  },
90
- aiText: {
91
- fontSize: 12,
92
- fontWeight: '400',
93
- marginLeft: 4,
380
+ androidLock: {
381
+ width: 30,
382
+ height: 30,
383
+ padding: 5,
384
+ marginLeft: 12,
94
385
  },
95
386
  });
@@ -15,19 +15,18 @@ import React from 'react';
15
15
  import { View, Text, useColorScheme, StyleSheet, TouchableOpacity } from 'react-native';
16
16
  import { COLORS } from '../util/Colors';
17
17
  import { Translations } from '../util/Translations';
18
- import { type ErrorState } from '../util/UIState';
19
18
 
20
19
  export interface ErrorProps {
21
20
  isDarkMode?: boolean;
22
- state: ErrorState
23
- onPress: () => void;
21
+ /** The localised text of the error. */
22
+ message: string;
23
+ /** Present exactly when the error is retryable; shows the retry button. */
24
+ onRetry: (() => void) | null;
24
25
  }
25
26
 
27
+ /** The default error part. */
26
28
  export const ErrorView: React.FC<ErrorProps> = (props) => {
27
29
  const isDarkMode = props.isDarkMode ?? useColorScheme() === 'dark';
28
- const state = props.state;
29
-
30
- const canBeRetried = (state.type === 'error' && state.canBeRetried)
31
30
 
32
31
  return (
33
32
  <View
@@ -36,14 +35,12 @@ export const ErrorView: React.FC<ErrorProps> = (props) => {
36
35
  isDarkMode ? { backgroundColor: COLORS.cardBgDark } : { backgroundColor: COLORS.cardBg }
37
36
  ]}>
38
37
 
39
- <Text
40
- style={[styles.text, state.type === 'error' ? styles.dangerText : (isDarkMode ? styles.darkText : styles.lightText)]}>
41
- {state.message}
38
+ <Text style={[styles.text, styles.dangerText]}>
39
+ {props.message}
42
40
  </Text>
43
41
 
44
-
45
- {canBeRetried && (
46
- <TouchableOpacity onPress={props.onPress} activeOpacity={0.9} style={[styles.button, isDarkMode ? { backgroundColor: '#fff' } : { backgroundColor: '#191919' }]}>
42
+ {props.onRetry != null && (
43
+ <TouchableOpacity onPress={props.onRetry} activeOpacity={0.9} style={[styles.button, isDarkMode ? { backgroundColor: '#fff' } : { backgroundColor: '#191919' }]}>
47
44
  {/* text should be centered */}
48
45
  <Text style={[styles.buttonText, isDarkMode ? styles.lightText : styles.darkText]}>
49
46
  {Translations.errorRetryNowButton()}