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
@@ -0,0 +1,144 @@
1
+ //===----------------------------------------------------------------------===//
2
+ //
3
+ // This source file is part of the LiveVoice SDK project
4
+ //
5
+ // Copyright (c) LiveVoice GmbH
6
+ // Licensed under the MIT license
7
+ //
8
+ // See LICENSE for license information
9
+ //
10
+ // SPDX-License-Identifier: MIT
11
+ //
12
+ //===----------------------------------------------------------------------===//
13
+
14
+ import { useEffect, useState } from 'react';
15
+ import { Modal, StyleSheet, Text, TextInput, TouchableOpacity, View } from 'react-native';
16
+
17
+ import { type PromptRequest } from '../sdk/Passwords';
18
+ import { COLORS } from '../util/Colors';
19
+ import { PasswordPromptTexts } from '../util/Translations';
20
+
21
+ export interface PasswordPromptProps {
22
+ request: PromptRequest;
23
+ isDarkMode: boolean;
24
+ /** The password, or `null` for Cancel. */
25
+ onAnswer: (password: string | null) => void;
26
+ }
27
+
28
+ /**
29
+ * The built-in password prompt, for channels and events alike. Its texts come from the native SDK;
30
+ * the title is the channel's or event's name, or "Password required" for a join.
31
+ */
32
+ export const PasswordPrompt: React.FC<PasswordPromptProps> = ({ request, isDarkMode, onAnswer }) => {
33
+ const [password, setPassword] = useState('');
34
+ // A new request starts empty.
35
+ useEffect(() => setPassword(''), [request.requestId]);
36
+
37
+ const isChannel = request.subject.kind === 'channel';
38
+ const text = isDarkMode ? COLORS.white : COLORS.black;
39
+ const confirm = () => { if (password.length > 0) onAnswer(password); };
40
+
41
+ return (
42
+ <Modal transparent animationType="fade" visible onRequestClose={() => onAnswer(null)}>
43
+ <View style={styles.backdrop}>
44
+ <View style={[styles.card, { backgroundColor: isDarkMode ? COLORS.cardBgDark : COLORS.cardBg }]}>
45
+ <Text accessibilityRole="header" style={[styles.title, { color: text }]}>
46
+ {request.name ?? PasswordPromptTexts.title()}
47
+ </Text>
48
+ <Text style={[styles.message, { color: text }]}>
49
+ {isChannel ? PasswordPromptTexts.channelMessage() : PasswordPromptTexts.eventMessage()}
50
+ </Text>
51
+ {request.isRetry && (
52
+ <Text accessibilityLiveRegion="polite" style={[styles.message, styles.wrong]}>
53
+ {PasswordPromptTexts.wrongPassword()}
54
+ </Text>
55
+ )}
56
+ <TextInput
57
+ value={password}
58
+ onChangeText={setPassword}
59
+ onSubmitEditing={confirm}
60
+ placeholder={PasswordPromptTexts.field()}
61
+ accessibilityLabel={PasswordPromptTexts.field()}
62
+ placeholderTextColor={isDarkMode ? '#8e8e93' : '#a0a0a5'}
63
+ secureTextEntry
64
+ autoFocus
65
+ autoCapitalize="none"
66
+ autoCorrect={false}
67
+ returnKeyType="go"
68
+ style={[styles.field, { color: text, borderColor: isDarkMode ? COLORS.dividerDark : COLORS.divider }]}
69
+ />
70
+ <View style={styles.buttons}>
71
+ <TouchableOpacity accessibilityRole="button" onPress={() => onAnswer(null)} style={styles.button}>
72
+ <Text style={[styles.buttonText, { color: text }]}>{PasswordPromptTexts.cancelButton()}</Text>
73
+ </TouchableOpacity>
74
+ <TouchableOpacity
75
+ accessibilityRole="button"
76
+ accessibilityState={{ disabled: password.length === 0 }}
77
+ disabled={password.length === 0}
78
+ onPress={confirm}
79
+ style={styles.button}
80
+ >
81
+ <Text style={[styles.buttonText, styles.confirm, { opacity: password.length === 0 ? 0.4 : 1 }]}>
82
+ {isChannel ? PasswordPromptTexts.channelConfirmButton() : PasswordPromptTexts.eventConfirmButton()}
83
+ </Text>
84
+ </TouchableOpacity>
85
+ </View>
86
+ </View>
87
+ </View>
88
+ </Modal>
89
+ );
90
+ };
91
+
92
+ const styles = StyleSheet.create({
93
+ backdrop: {
94
+ flex: 1,
95
+ justifyContent: 'center',
96
+ alignItems: 'center',
97
+ padding: 24,
98
+ backgroundColor: 'rgba(0, 0, 0, 0.4)',
99
+ },
100
+ card: {
101
+ width: '100%',
102
+ maxWidth: 360,
103
+ borderRadius: 14,
104
+ padding: 20,
105
+ },
106
+ title: {
107
+ fontSize: 17,
108
+ fontWeight: '600',
109
+ textAlign: 'center',
110
+ },
111
+ message: {
112
+ fontSize: 14,
113
+ textAlign: 'center',
114
+ marginTop: 8,
115
+ },
116
+ wrong: {
117
+ color: '#F1521B',
118
+ },
119
+ field: {
120
+ borderWidth: 1,
121
+ borderRadius: 8,
122
+ paddingHorizontal: 12,
123
+ paddingVertical: 10,
124
+ marginTop: 16,
125
+ fontSize: 16,
126
+ },
127
+ buttons: {
128
+ flexDirection: 'row',
129
+ justifyContent: 'flex-end',
130
+ marginTop: 16,
131
+ },
132
+ button: {
133
+ paddingHorizontal: 12,
134
+ paddingVertical: 8,
135
+ marginLeft: 8,
136
+ },
137
+ buttonText: {
138
+ fontSize: 16,
139
+ fontWeight: '500',
140
+ },
141
+ confirm: {
142
+ color: COLORS.primary,
143
+ },
144
+ });
@@ -11,18 +11,18 @@
11
11
  //
12
12
  //===----------------------------------------------------------------------===//
13
13
 
14
- import { COLORS } from "../util/Colors";
15
14
  import {
16
- ActivityIndicator,
17
15
  Image,
16
+ Platform,
18
17
  TouchableOpacity,
19
18
  useColorScheme,
20
19
  View,
21
20
  } from "react-native";
22
- import { PlayingState } from "../util/PlayingState";
21
+ import { type LiveVoicePlayingState } from "../sdk/Models";
22
+ import { LiveVoiceSpinner } from "./LiveVoiceSpinner";
23
23
 
24
24
  export interface PlayButtonProps {
25
- playingState: PlayingState;
25
+ playingState: LiveVoicePlayingState;
26
26
  isChannelOnline: boolean;
27
27
  hasAudio?: boolean;
28
28
  hasSubtitles?: boolean;
@@ -30,8 +30,18 @@ export interface PlayButtonProps {
30
30
  onAudioPress?: () => void;
31
31
  onSubtitlesPress?: () => void;
32
32
  onPress?: () => void;
33
+ /** The event's brand colour for this appearance; LiveVoice orange when `null`. */
34
+ brandColor?: string | null;
35
+ /** Whether this channel's subtitles are the open ones: the subtitle half is marked. */
36
+ subtitlesOpen?: boolean;
33
37
  }
34
38
 
39
+ /**
40
+ * The default cell's play button, drawn as the native SDK of the platform draws it: iOS
41
+ * `ChannelPlayButton` in its `.sdk` style, Android `PlayButton` in the SDK cell's Listener style.
42
+ * Change them together. Geometry is the same on both; the colours are each platform's own
43
+ * (`buttonColors`).
44
+ */
35
45
  const PlayButtonView: React.FC<PlayButtonProps> = ({
36
46
  playingState,
37
47
  isChannelOnline,
@@ -41,72 +51,52 @@ const PlayButtonView: React.FC<PlayButtonProps> = ({
41
51
  onAudioPress,
42
52
  onSubtitlesPress,
43
53
  onPress,
54
+ brandColor = null,
55
+ subtitlesOpen = false,
44
56
  }) => {
45
- const isPlaying = playingState === PlayingState.PLAYING;
46
- const isTransitioning = playingState === PlayingState.TRANSITIONING;
47
-
48
- const getAudioIconColor = () => {
49
- if (!isChannelOnline) {
50
- return isDarkMode ? "#5a5a60" : "#d1d1d6";
51
- }
52
- return COLORS.white;
53
- };
54
-
55
- const getSubtitlesIconColor = () => {
56
- if (!isChannelOnline) {
57
- return isDarkMode ? "#ffffff" : "#000000";
58
- }
59
- return COLORS.white;
60
- };
61
-
62
- const audioIconColor = getAudioIconColor();
63
- const subtitlesIconColor = getSubtitlesIconColor();
64
-
65
- const getAudioIcon = () => {
66
- if (isTransitioning) {
67
- return <ActivityIndicator size={20} color={audioIconColor} style={{}} />;
68
- }
69
- return isPlaying ? (
70
- <Image
71
- source={require("../icons/pause.png")}
72
- style={[{ tintColor: audioIconColor, width: 30, height: 26 }]}
73
- />
74
- ) : (
57
+ const isPlaying = playingState === "playing";
58
+ const isTransitioning = playingState === "transitioning";
59
+ const colors = buttonColors(isDarkMode);
60
+
61
+ // Play, pause and the spinner share one colour by state, as both native glyphs do.
62
+ const glyphColor = isChannelOnline ? colors.onlineGlyph : colors.offlineGlyph;
63
+ const captionsColor = isChannelOnline ? colors.onlineGlyph : colors.offlineCaptions;
64
+ // The event's brand colour replaces the orange of an online button.
65
+ const fill = isChannelOnline ? brandColor ?? colors.onlineFill : colors.offlineFill;
66
+
67
+ const audioIcon = isTransitioning
68
+ ? <LiveVoiceSpinner size={22} color={glyphColor} />
69
+ : (
75
70
  <Image
76
- source={require("../icons/play.png")}
77
- style={[{ tintColor: audioIconColor, width: 30, height: 26 }]}
71
+ source={isPlaying ? require("../icons/pause.png") : require("../icons/play.png")}
72
+ style={[{ tintColor: glyphColor, width: 30, height: 26 }]}
78
73
  />
79
74
  );
80
- };
81
-
82
- const getSubtitlesIcon = () => {
83
- return (
84
- <Image
85
- source={require("../icons/captions.png")}
86
- style={[{ tintColor: subtitlesIconColor, width: 30, height: 26 }]}
87
- />
88
- );
89
- };
75
+ const subtitlesIcon = (
76
+ <Image
77
+ source={require("../icons/captions.png")}
78
+ style={[{ tintColor: captionsColor, width: 30, height: 26 }]}
79
+ />
80
+ );
90
81
 
91
- const getStyleType = () => {
92
- if (!isChannelOnline) return "offline";
93
- if (isPlaying) return "playing";
94
- return "paused";
95
- };
82
+ // Open subtitles mark the subtitle half with a capsule, as both native SDKs do.
83
+ const marker = (inset: number) => subtitlesOpen && (
84
+ <SubtitlesMarker inset={inset} color={isChannelOnline ? colors.onlineMarker : colors.offlineMarker} />
85
+ );
86
+ // The offline outline, over the button without taking any of its room.
87
+ const border = !isChannelOnline && <ButtonBorder color={colors.outline} />;
96
88
 
97
- // If no audio and no subtitles, render disabled button with dashed border
89
+ // Neither audio nor subtitles: a dashed outline and nothing to press.
98
90
  if (!hasAudio && !hasSubtitles) {
99
- const noContentStyle = {
100
- ...baseButtonStyleNoContent,
101
- backgroundColor: isDarkMode ? "#1c1c1e00" : "#ffffff",
102
- borderColor: isDarkMode
103
- ? COLORS_SCHEME.borderGrayDark
104
- : COLORS_SCHEME.borderGrayLight,
105
- borderStyle: "dashed" as const,
106
- };
107
91
  return (
108
92
  <TouchableOpacity
109
- style={noContentStyle}
93
+ style={{
94
+ ...buttonFrame,
95
+ borderWidth: colors.noInputBorderWidth,
96
+ borderColor: colors.outline,
97
+ borderStyle: "dashed",
98
+ backgroundColor: isChannelOnline && colors.noInputFillsWhenOnline ? fill : colors.noInputFill,
99
+ }}
110
100
  disabled={true}
111
101
  activeOpacity={0.8}
112
102
  >
@@ -115,262 +105,168 @@ const PlayButtonView: React.FC<PlayButtonProps> = ({
115
105
  );
116
106
  }
117
107
 
118
- // If only audio, render simple button
119
- if (hasAudio && !hasSubtitles) {
108
+ if (!hasSubtitles) {
120
109
  return (
121
110
  <TouchableOpacity
122
- style={getButtonStyle(getStyleType(), isDarkMode, false)}
111
+ style={[buttonFrame, { backgroundColor: fill }]}
123
112
  onPress={onAudioPress || onPress}
124
113
  activeOpacity={0.8}
125
114
  >
126
- {getAudioIcon()}
115
+ {audioIcon}
116
+ {border}
127
117
  </TouchableOpacity>
128
118
  );
129
119
  }
130
120
 
131
- // If only subtitles, render subtitles button
132
- if (!hasAudio && hasSubtitles) {
121
+ if (!hasAudio) {
133
122
  return (
134
123
  <TouchableOpacity
135
- style={getButtonStyle(getStyleType(), isDarkMode, false)}
124
+ style={[buttonFrame, { backgroundColor: fill }]}
136
125
  onPress={onSubtitlesPress || onPress}
137
126
  activeOpacity={0.8}
138
127
  >
139
- {getSubtitlesIcon()}
128
+ {marker(3)}
129
+ {subtitlesIcon}
130
+ {border}
140
131
  </TouchableOpacity>
141
132
  );
142
133
  }
143
134
 
144
- // If both audio and subtitles, render split button
135
+ // The divider keeps its slot but is clear while the channel plays or its subtitles are open.
136
+ const dividerColor = isPlaying || subtitlesOpen
137
+ ? "transparent"
138
+ : isChannelOnline ? colors.onlineDivider : colors.offlineDivider;
145
139
  return (
146
- <View style={getSplitButtonContainerStyle(getStyleType(), isDarkMode)}>
147
- <TouchableOpacity
148
- style={getSplitButtonAudioStyle(getStyleType(), isDarkMode)}
149
- onPress={onAudioPress || onPress}
150
- activeOpacity={0.8}
151
- >
152
- {getAudioIcon()}
140
+ <View style={[splitFrame, { backgroundColor: fill }]}>
141
+ <TouchableOpacity style={halfFrame} onPress={onAudioPress || onPress} activeOpacity={0.8}>
142
+ {audioIcon}
153
143
  </TouchableOpacity>
154
- <View style={getDividerStyle(getStyleType(), isDarkMode)} />
155
- <TouchableOpacity
156
- style={getSplitButtonSubtitlesStyle(getStyleType(), isDarkMode)}
157
- onPress={onSubtitlesPress || onPress}
158
- activeOpacity={0.8}
159
- >
160
- {getSubtitlesIcon()}
144
+ <View style={[dividerFrame, { backgroundColor: dividerColor }]} />
145
+ <TouchableOpacity style={halfFrame} onPress={onSubtitlesPress || onPress} activeOpacity={0.8}>
146
+ {marker(4)}
147
+ {subtitlesIcon}
161
148
  </TouchableOpacity>
149
+ {border}
162
150
  </View>
163
151
  );
164
152
  };
165
153
 
166
- type ButtonStyleType = "paused" | "playing" | "offline";
167
-
168
- export const getButtonStyle = (
169
- type: ButtonStyleType,
170
- isDarkMode: boolean,
171
- isSplit: boolean = false,
172
- ) => {
173
- if (isSplit) {
174
- return SplitButtonStyles[type][isDarkMode ? "dark" : "light"].container;
175
- }
176
- return ButtonStyles[type][isDarkMode ? "dark" : "light"];
177
- };
178
-
179
- export const getSplitButtonContainerStyle = (
180
- type: ButtonStyleType,
181
- isDarkMode: boolean,
182
- ) => {
183
- return SplitButtonStyles[type][isDarkMode ? "dark" : "light"].container;
184
- };
185
-
186
- export const getSplitButtonAudioStyle = (
187
- type: ButtonStyleType,
188
- isDarkMode: boolean,
189
- ) => {
190
- return SplitButtonStyles[type][isDarkMode ? "dark" : "light"].audio;
191
- };
192
-
193
- export const getSplitButtonSubtitlesStyle = (
194
- type: ButtonStyleType,
195
- isDarkMode: boolean,
196
- ) => {
197
- return SplitButtonStyles[type][isDarkMode ? "dark" : "light"].subtitles;
198
- };
199
-
200
- export const getDividerStyle = (type: ButtonStyleType, isDarkMode: boolean) => {
201
- // When button is online (orange background), divider is light orange
202
- if (type === "paused" || type === "playing") {
154
+ /**
155
+ * Every colour of the button, light or dark, as the native SDK of this platform has it.
156
+ *
157
+ * Both: LiveVoice orange online (iOS `.lvOrange`, Android `orange`); white glyphs online; the
158
+ * outline and the offline divider `#A0A0A0` / `#E0E0E0` at 50 % (iOS `.lightGrey.opacity(0.5)`,
159
+ * Android `playButtonOutline`); the online divider white at 30 %; the marker white at 25 % online,
160
+ * `#EAEAEF` / `#4E4E4E` offline (iOS `.outlineButtonBorder`, Android
161
+ * `selectedCaptionsBackgroundOffline`).
162
+ *
163
+ * - iOS (`ChannelPlayButton`, `.sdk`): offline fill `.clear`; offline play glyph, pause and spinner
164
+ * `.lightGrey.opacity(0.5)`; offline captions `.primary`.
165
+ * - Android (`PlayButton`, Listener, in `LvAppTheme`): offline fill `background` (`white`,
166
+ * `veryDarkGray`); offline play glyph, pause and spinner `buttonIconInactive` (`veryLightGray`,
167
+ * `darkGray`); offline captions `onBackground` (`lightBlack`, `white`).
168
+ * - The button without input follows iOS on both: filled as an online button when its channel is
169
+ * online, clear otherwise, with a 1 pt dashed outline (Android is changing to match).
170
+ */
171
+ function buttonColors(isDarkMode: boolean) {
172
+ const outline = isDarkMode ? "rgba(224, 224, 224, 0.5)" : "rgba(160, 160, 160, 0.5)";
173
+ const shared = {
174
+ onlineFill: "#F56230",
175
+ onlineGlyph: "#FFFFFF",
176
+ outline,
177
+ onlineDivider: "rgba(255, 255, 255, 0.3)",
178
+ offlineDivider: outline,
179
+ onlineMarker: "rgba(255, 255, 255, 0.25)",
180
+ offlineMarker: isDarkMode ? "#4E4E4E" : "#EAEAEF",
181
+ // Without audio or subtitles, both as iOS: filled as an online button when the channel is
182
+ // online, clear otherwise, and always the 1 pt dashed outline.
183
+ noInputFill: "transparent",
184
+ noInputFillsWhenOnline: true,
185
+ noInputBorderWidth: 1,
186
+ };
187
+ if (Platform.OS === "ios") {
203
188
  return {
204
- width: 1,
205
- height: 24,
206
- backgroundColor: COLORS_SCHEME.dividerOnOrange,
189
+ ...shared,
190
+ offlineFill: "transparent",
191
+ offlineGlyph: outline,
192
+ offlineCaptions: isDarkMode ? "#FFFFFF" : "#000000",
207
193
  };
208
194
  }
209
-
210
- // When button is offline, divider is gray (same as border)
195
+ const background = isDarkMode ? "#212529" : "#FFFFFF";
211
196
  return {
212
- width: 1,
213
- height: 24,
214
- backgroundColor: isDarkMode
215
- ? COLORS_SCHEME.borderGrayDark
216
- : COLORS_SCHEME.borderGrayLight,
197
+ ...shared,
198
+ offlineFill: background,
199
+ offlineGlyph: isDarkMode ? "#343A40" : "#E7E7E7",
200
+ offlineCaptions: isDarkMode ? "#FFFFFF" : "#191919",
217
201
  };
218
- };
219
-
220
- const baseButtonStyle = {
221
- width: 96,
222
- height: 44,
223
- borderRadius: 22,
224
- borderWidth: 1,
225
- alignItems: "center" as const,
226
- justifyContent: "center" as const,
227
- };
202
+ }
228
203
 
229
- const baseButtonStyleNoContent = {
204
+ /**
205
+ * The open-subtitles marker, drawn as the native SDKs draw it: a capsule inset `inset` from the
206
+ * subtitle half's own bounds, 4 beside the play half and 3 on a subtitles-only button.
207
+ */
208
+ const SubtitlesMarker: React.FC<{ inset: number; color: string }> = ({ inset, color }) => (
209
+ <View
210
+ style={{
211
+ position: "absolute",
212
+ top: inset,
213
+ bottom: inset,
214
+ left: inset,
215
+ right: inset,
216
+ borderRadius: (buttonFrame.height - 2 * inset) / 2,
217
+ backgroundColor: color,
218
+ }}
219
+ />
220
+ );
221
+
222
+ /**
223
+ * The offline button's 1 pt outline, drawn over the button as both native SDKs stroke it (iOS
224
+ * `strokeBorder` in the button's background, Android `Modifier.border`), so it insets nothing: the
225
+ * halves fill the whole 96 × 44 button and the glyphs sit where native puts them. Online, iOS draws
226
+ * none and Android strokes it in the fill's own colour, so none is drawn here.
227
+ */
228
+ const ButtonBorder: React.FC<{ color: string }> = ({ color }) => (
229
+ <View
230
+ pointerEvents="none"
231
+ style={{
232
+ position: "absolute",
233
+ top: 0,
234
+ bottom: 0,
235
+ left: 0,
236
+ right: 0,
237
+ borderRadius: buttonFrame.borderRadius,
238
+ borderWidth: 1,
239
+ borderColor: color,
240
+ }}
241
+ />
242
+ );
243
+
244
+ // No border of their own: an offline outline is `ButtonBorder`, which takes no room.
245
+ const buttonFrame = {
230
246
  width: 96,
231
247
  height: 44,
232
248
  borderRadius: 22,
233
- borderWidth: 1,
234
249
  alignItems: "center" as const,
235
250
  justifyContent: "center" as const,
236
251
  };
237
252
 
238
- const baseSplitButtonStyle = {
239
- width: 96,
240
- height: 44,
241
- borderRadius: 22,
242
- borderWidth: 1,
253
+ const splitFrame = {
254
+ ...buttonFrame,
243
255
  flexDirection: "row" as const,
244
- alignItems: "center" as const,
245
- justifyContent: "center" as const,
246
256
  overflow: "hidden" as const,
247
257
  };
248
258
 
249
- const baseSplitAudioStyle = {
250
- flex: 1,
251
- height: 44,
252
- alignItems: "center" as const,
253
- justifyContent: "center" as const,
254
- };
255
-
256
- const baseSplitSubtitlesStyle = {
259
+ const halfFrame = {
257
260
  flex: 1,
258
261
  height: 44,
259
262
  alignItems: "center" as const,
260
263
  justifyContent: "center" as const,
261
264
  };
262
265
 
263
- const COLORS_SCHEME = {
264
- orange: "#f56230",
265
- dividerOnOrange: "#ffffff80",
266
- borderGrayLight: "#d1d1d6",
267
- borderGrayDark: "#5a5a60",
268
- };
269
-
270
- export const ButtonStyles = {
271
- paused: {
272
- light: {
273
- ...baseButtonStyle,
274
- backgroundColor: COLORS_SCHEME.orange,
275
- borderColor: "transparent",
276
- },
277
- dark: {
278
- ...baseButtonStyle,
279
- backgroundColor: COLORS_SCHEME.orange,
280
- borderColor: "transparent",
281
- },
282
- },
283
-
284
- playing: {
285
- light: {
286
- ...baseButtonStyle,
287
- backgroundColor: COLORS_SCHEME.orange,
288
- borderColor: "transparent",
289
- },
290
- dark: {
291
- ...baseButtonStyle,
292
- backgroundColor: COLORS_SCHEME.orange,
293
- borderColor: "transparent",
294
- },
295
- },
296
-
297
- offline: {
298
- light: {
299
- ...baseButtonStyle,
300
- backgroundColor: "#ffffff",
301
- borderColor: COLORS_SCHEME.borderGrayLight,
302
- },
303
- dark: {
304
- ...baseButtonStyle,
305
- backgroundColor: "#212429",
306
- borderColor: COLORS_SCHEME.borderGrayDark,
307
- },
308
- },
309
- };
310
-
311
- export const SplitButtonStyles = {
312
- paused: {
313
- light: {
314
- container: {
315
- ...baseSplitButtonStyle,
316
- backgroundColor: COLORS_SCHEME.orange,
317
- borderColor: "transparent",
318
- },
319
- audio: baseSplitAudioStyle,
320
- subtitles: baseSplitSubtitlesStyle,
321
- },
322
- dark: {
323
- container: {
324
- ...baseSplitButtonStyle,
325
- backgroundColor: COLORS_SCHEME.orange,
326
- borderColor: "transparent",
327
- },
328
- audio: baseSplitAudioStyle,
329
- subtitles: baseSplitSubtitlesStyle,
330
- },
331
- },
332
-
333
- playing: {
334
- light: {
335
- container: {
336
- ...baseSplitButtonStyle,
337
- backgroundColor: COLORS_SCHEME.orange,
338
- borderColor: "transparent",
339
- },
340
- audio: baseSplitAudioStyle,
341
- subtitles: baseSplitSubtitlesStyle,
342
- },
343
- dark: {
344
- container: {
345
- ...baseSplitButtonStyle,
346
- backgroundColor: COLORS_SCHEME.orange,
347
- borderColor: "transparent",
348
- },
349
- audio: baseSplitAudioStyle,
350
- subtitles: baseSplitSubtitlesStyle,
351
- },
352
- },
353
-
354
- offline: {
355
- light: {
356
- container: {
357
- ...baseSplitButtonStyle,
358
- backgroundColor: "#ffffff",
359
- borderColor: COLORS_SCHEME.borderGrayLight,
360
- },
361
- audio: baseSplitAudioStyle,
362
- subtitles: baseSplitSubtitlesStyle,
363
- },
364
- dark: {
365
- container: {
366
- ...baseSplitButtonStyle,
367
- backgroundColor: "#212429",
368
- borderColor: COLORS_SCHEME.borderGrayDark,
369
- },
370
- audio: baseSplitAudioStyle,
371
- subtitles: baseSplitSubtitlesStyle,
372
- },
373
- },
266
+ // 26 tall, 9 from the top and bottom of the 44 button, as in both native SDKs.
267
+ const dividerFrame = {
268
+ width: 1,
269
+ height: 26,
374
270
  };
375
271
 
376
272
  export default PlayButtonView;