Skip to content

Commit e05de19

Browse files
committed
fix: default recorder sampleFormat
1 parent 2788510 commit e05de19

File tree

27 files changed

+364
-1015
lines changed

27 files changed

+364
-1015
lines changed

apps/common-app/src/App.tsx

Lines changed: 60 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,31 @@ import { colors, layout } from './styles';
2121

2222
const Stack = createStackNavigator();
2323

24-
const ItemSeparatorComponent = () => <Spacer.Vertical size={16} />;
25-
26-
const ItemSeparatorComponent2 = () => (
27-
<View>
28-
<Spacer.Vertical size={12} />
29-
<View style={styles.hr} />
30-
<Spacer.Vertical size={12} />
31-
</View>
32-
);
33-
34-
const ExamplesScreen: FC = () => {
24+
const TestsScreen: FC = () => {
3525
const navigation = useNavigation<MainStackProps>();
3626

3727
const renderItem: ListRenderItem<Example> = ({
38-
item: { Icon, key, subtitle, title },
28+
item: { Icon, key, title },
3929
}) => (
4030
<Pressable
4131
key={key}
4232
style={styles.buttonSmall}
4333
onPress={() => navigation.navigate(key)}
4434
>
45-
{/* <Icon /> */}
46-
<Text style={styles.subtitleSmall}>{subtitle}</Text>
35+
<Icon color={colors.white} size={18} />
4736
<Text style={styles.titleSmall}>{title}</Text>
4837
</Pressable>
4938
);
5039

5140
return (
52-
<Container>
41+
<Container headless>
5342
<FlatList
5443
data={Examples}
5544
renderItem={renderItem}
5645
keyExtractor={(item) => item.key}
5746
contentContainerStyle={styles.scrollView}
58-
ItemSeparatorComponent={ItemSeparatorComponent2}
47+
ItemSeparatorComponent={ItemSeparatorComponentSmall}
48+
numColumns={2}
5949
/>
6050
</Container>
6151
);
@@ -73,13 +63,16 @@ const DemoAppsScreen: FC = () => {
7363
{ borderStyle: pressed ? 'solid' : 'dashed' },
7464
]}
7565
>
76-
<Text style={styles.title}>{item.title}</Text>
77-
<Text style={styles.subtitle}>{item.subtitle}</Text>
66+
<item.icon color={colors.white} size={24} />
67+
<View style={styles.buttonInner}>
68+
<Text style={styles.title}>{item.title}</Text>
69+
<Text style={styles.subtitle}>{item.subtitle}</Text>
70+
</View>
7871
</Pressable>
7972
);
8073

8174
return (
82-
<Container>
75+
<Container headless>
8376
<FlatList
8477
data={demos}
8578
renderItem={renderItem}
@@ -91,26 +84,26 @@ const DemoAppsScreen: FC = () => {
9184
);
9285
};
9386

94-
const BenchmarksScreen: FC = () => {
95-
return <Container />;
87+
const OtherScreen: FC = () => {
88+
return <Container headless />;
9689
};
9790

9891
const MainTabs = createNativeBottomTabNavigator<MainStackProps>({
9992
screens: {
100-
Examples: ExamplesScreen,
93+
Tests: TestsScreen,
10194
DemoApps: DemoAppsScreen,
102-
Benchmarks: BenchmarksScreen,
95+
Other: OtherScreen,
10396
},
10497
});
10598

10699
const MainTabsScreen: FC = () => {
107100
return (
108101
<MainTabs.Navigator>
109102
<MainTabs.Screen
110-
name="Examples"
111-
component={ExamplesScreen}
103+
name="Tests"
104+
component={TestsScreen}
112105
options={{
113-
title: 'Examples',
106+
title: 'Tests',
114107
tabBarIcon: {
115108
type: 'sfSymbol',
116109
name: 'list.number',
@@ -129,10 +122,10 @@ const MainTabsScreen: FC = () => {
129122
}}
130123
/>
131124
<MainTabs.Screen
132-
name="Benchmarks"
133-
component={BenchmarksScreen}
125+
name="Other"
126+
component={OtherScreen}
134127
options={{
135-
title: 'Benchmarks',
128+
title: 'Other',
136129

137130
tabBarIcon: {
138131
type: 'sfSymbol',
@@ -189,6 +182,16 @@ const App: FC = () => {
189182

190183
export default App;
191184

185+
const ItemSeparatorComponent = () => <Spacer.Vertical size={16} />;
186+
187+
const ItemSeparatorComponentSmall = () => (
188+
<View>
189+
<Spacer.Vertical size={6} />
190+
<View style={styles.hr} />
191+
<Spacer.Vertical size={6} />
192+
</View>
193+
);
194+
192195
const styles = StyleSheet.create({
193196
container: {
194197
flex: 1,
@@ -197,6 +200,7 @@ const styles = StyleSheet.create({
197200
fontSize: 24,
198201
fontWeight: '700',
199202
color: colors.white,
203+
lineHeight: 24,
200204
},
201205
subtitle: {
202206
opacity: 0.6,
@@ -208,24 +212,45 @@ const styles = StyleSheet.create({
208212
borderRadius: layout.radius,
209213
paddingVertical: layout.spacing * 2,
210214
paddingHorizontal: layout.spacing * 2,
215+
flexDirection: 'row',
216+
alignItems: 'flex-start',
217+
gap: layout.spacing,
218+
},
219+
buttonInner: {
220+
flexShrink: 1,
211221
},
212222
buttonSmall: {
213-
paddingVertical: layout.spacing,
214-
paddingHorizontal: layout.spacing * 2,
223+
padding: layout.spacing,
224+
flexDirection: 'row',
225+
alignItems: 'center',
226+
gap: layout.spacing,
227+
width: '48%',
228+
margin: '1%',
229+
height: 40,
230+
borderWidth: StyleSheet.hairlineWidth,
231+
borderColor: colors.white,
215232
},
216233
titleSmall: {
217-
fontSize: 18,
234+
fontSize: 16,
218235
fontWeight: '600',
219236
color: colors.white,
237+
marginLeft: 4,
238+
flexShrink: 1,
220239
},
221240
subtitleSmall: {
222241
opacity: 0.6,
223242
color: colors.white,
224243
},
225244
scrollView: {},
226245
hr: {
227-
height: StyleSheet.hairlineWidth,
228-
backgroundColor: colors.border,
229-
marginHorizontal: 64,
246+
// height: StyleSheet.hairlineWidth,
247+
// // backgroundColor: colors.border,
248+
// marginLeft: 60,
249+
// marginRight: '35%',
250+
},
251+
row: {
252+
flexDirection: 'row',
253+
alignItems: 'center',
254+
gap: layout.spacing,
230255
},
231256
});

apps/common-app/src/components/Container.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,23 @@ type ContainerProps = PropsWithChildren<{
88
style?: StyleProp<ViewStyle>;
99
centered?: boolean;
1010
disablePadding?: boolean;
11+
headless?: boolean;
1112
}>;
1213

1314
const headerPadding = 120; // eyeballed
1415

1516
const Container: React.FC<ContainerProps> = (props) => {
16-
const { children, style, centered, disablePadding } = props;
17+
const { children, style, centered, disablePadding, headless } = props;
1718

1819
return (
1920
<SafeAreaView
20-
edges={['bottom', 'left', 'right']}
21+
edges={
22+
headless
23+
? ['bottom', 'left', 'right', 'top']
24+
: ['bottom', 'left', 'right']
25+
}
2126
style={[
22-
styles.basic,
27+
headless ? styles.basicHeadless : styles.basic,
2328
centered && styles.centered,
2429
!disablePadding && styles.padding,
2530
style,
@@ -38,8 +43,13 @@ const styles = StyleSheet.create({
3843
paddingTop: headerPadding,
3944
backgroundColor: colors.background,
4045
},
46+
basicHeadless: {
47+
flex: 1,
48+
backgroundColor: colors.background,
49+
paddingTop: 20,
50+
},
4151
padding: {
42-
padding: 24,
52+
paddingHorizontal: 18,
4353
},
4454
centered: {
4555
alignItems: 'center',

apps/common-app/src/demos/Record/Record.tsx

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { FC, useCallback, useEffect, useState } from 'react';
2-
import { AudioContext, AudioManager } from 'react-native-audio-api';
2+
import { AudioManager } from 'react-native-audio-api';
33

44
import { Alert, StyleSheet, View } from 'react-native';
55
import { Container } from '../../components';
@@ -17,8 +17,6 @@ AudioManager.setAudioSessionOptions({
1717
iosOptions: ['defaultToSpeaker', 'allowBluetoothA2DP'],
1818
});
1919

20-
const audioContext = new AudioContext({ initSuspended: true });
21-
2220
Recorder.enableFileOutput({});
2321

2422
const Record: FC = () => {
@@ -160,42 +158,3 @@ const styles = StyleSheet.create({
160158
spacerM: { height: 24 },
161159
spacerS: { height: 12 },
162160
});
163-
164-
// const [lastOutput, setLastOutput] = useState<string | null>(null);
165-
166-
// useEffect(() => {
167-
// recorder.onError((error) => {
168-
// console.error('Recorder error:', error);
169-
// Alert.alert('Recorder Error', error.message);
170-
// });
171-
172-
// return () => {
173-
// recorder.clearOnError();
174-
// };
175-
// }, []);
176-
177-
// const onPlayOutput = useCallback(async () => {
178-
// if (!lastOutput || state !== ExampleState.Idle) {
179-
// return;
180-
// }
181-
182-
// setState(ExampleState.Playing);
183-
184-
// await AudioManager.setAudioSessionActivity(true);
185-
186-
// const buffer = await audioContext.decodeAudioData(lastOutput);
187-
// const source = audioContext.createBufferSource();
188-
// source.buffer = buffer;
189-
// source.connect(audioContext.destination);
190-
// source.start();
191-
192-
// source.onEnded = async () => {
193-
// await audioContext.suspend();
194-
// await AudioManager.setAudioSessionActivity(false);
195-
// setState(ExampleState.Idle);
196-
// };
197-
198-
// if (audioContext.state === 'suspended') {
199-
// await audioContext.resume();
200-
// }
201-
// }, [lastOutput, state]);

apps/common-app/src/demos/Record/RecordingVisualization.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ interface RecordingVisualizationProps {
1818

1919
const constants = {
2020
sampleRate: 3125,
21-
updateIntervalMS: 32,
22-
barWidth: 3,
21+
updateIntervalMS: 42,
22+
barWidth: 2,
2323
barGap: 2,
2424
minDb: -40,
2525
maxDb: 0,

apps/common-app/src/demos/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1+
import { icons } from 'lucide-react-native';
2+
13
import Record from './Record/Record';
24

5+
interface SimplifiedIconProps {
6+
color?: string;
7+
size?: number;
8+
}
9+
310
export interface DemoScreen {
411
key: string;
512
title: string;
613
subtitle: string;
14+
icon: React.FC<SimplifiedIconProps>;
715
screen: React.FC;
816
}
917

1018
export const demos: DemoScreen[] = [
1119
{
1220
key: 'RecordDemo',
13-
title: 'Recording',
14-
subtitle: 'Record and play audio',
21+
title: 'Recorder',
22+
subtitle:
23+
'Demonstrates microphone permissions, capture, and playback similar to voice memos app.',
24+
icon: icons.Mic,
1525
screen: Record,
1626
},
1727
] as const;

apps/common-app/src/examples/Record/ControlPanel.tsx

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)