Skip to content

Commit bc20c3d

Browse files
audio player props and styling options (#529)
* audio player props and styling options * typo correction * audio player props and styling options * Shrink Names To Fit in Properties Panel * updated default colors * Try without cache * Try new builder bob version * Try Try again * Update yarn.lock Co-authored-by: Brian Luerssen <[email protected]> Co-authored-by: Brian Luerssen <[email protected]>
1 parent 5808fa1 commit bc20c3d

File tree

13 files changed

+758
-511
lines changed

13 files changed

+758
-511
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,11 @@ jobs:
1717

1818
- uses: actions/setup-node@v3
1919
with:
20-
node-version: 16.16
20+
node-version: 16.18
2121
registry-url: https://registry.npmjs.org/
2222

23-
# With lerna/workspaces, the cache is at the monorepo level.
24-
- name: Restore node_modules cache
25-
uses: actions/cache@v3
26-
id: yarn-cache # use this to check for `cache-hit`
27-
with:
28-
path: "node_modules"
29-
key: node_modules-${{ hashFiles('yarn.lock') }}
30-
3123
- name: Install Dependencies
32-
if: steps.yarn-cache.outputs.cache-hit != 'true'
33-
run: yarn install --frozen-lockfile
24+
run: yarn install
3425

3526
- name: Type Check
3627
run: yarn typescript

example/src/AudioPlayerExample.tsx

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,51 @@ export default function AudioPlayerExample() {
66
return (
77
<ScreenContainer hasSafeArea={false} scrollable={false}>
88
<Text> Local asset value </Text>
9-
<AudioPlayer source={require("./assets/loop.wav")} />
9+
<AudioPlayer
10+
style={{
11+
backgroundColor: "#eee",
12+
paddingLeft: 8,
13+
paddingRight: 8,
14+
paddingTop: 8,
15+
paddingBottom: 8,
16+
borderRadius: 24,
17+
marginBottom: 20,
18+
fontWeight: "bold",
19+
height: 40,
20+
width: "80%",
21+
}}
22+
source={require("./assets/loop.wav")}
23+
sliderColor="red"
24+
completedTrackColor="white"
25+
remainingTrackColor="#999999"
26+
playSize={18}
27+
/>
28+
<AudioPlayer
29+
style={{
30+
backgroundColor: "#333",
31+
padding: 8,
32+
margin: 8,
33+
marginBottom: 20,
34+
borderRadius: 4,
35+
color: "#fff",
36+
}}
37+
source={require("./assets/loop.wav")}
38+
sliderColor="white"
39+
completedTrackColor="white"
40+
remainingTrackColor="#dedede"
41+
playSize={18}
42+
playColor="#fff"
43+
/>
1044
<Text> Remote value </Text>
1145
<AudioPlayer
46+
style={{
47+
paddingLeft: 20,
48+
paddingRight: 20,
49+
paddingTop: 8,
50+
paddingBottom: 8,
51+
color: "red",
52+
fontSize: 14,
53+
}}
1254
source={{
1355
uri: "https://static.draftbit.com/audio/intro-to-draftbit-audio.mp3",
1456
}}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@
4646
"husky": ">=6",
4747
"jest": "^26.6.3",
4848
"json-server": "^0.16.3",
49-
"lerna": "^5.1.4",
49+
"lerna": "^5.6.2",
5050
"lint-staged": ">=13",
5151
"node-fetch": "^2.6.1",
5252
"patch-package": "^6.4.7",
5353
"postinstall-postinstall": "^2.1.0",
5454
"prettier": "^2.7.1",
55-
"react-native-builder-bob": "^0.18.3",
55+
"react-native-builder-bob": "^0.20.3",
5656
"rimraf": "^3.0.2",
5757
"ts-node": "^10.0.0",
5858
"typescript": "~4.7.4",

packages/core/package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,18 @@
7070
"source": "src",
7171
"output": "lib",
7272
"targets": [
73-
"commonjs",
74-
"module",
73+
[
74+
"commonjs",
75+
{
76+
"sourceMaps": false
77+
}
78+
],
79+
[
80+
"module",
81+
{
82+
"sourceMaps": false
83+
}
84+
],
7585
[
7686
"typescript",
7787
{

packages/core/src/mappings/AudioPlayer.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,34 @@ import {
33
COMPONENT_TYPES,
44
FORM_TYPES,
55
PROP_TYPES,
6+
StylesPanelSections,
7+
createColorProp,
8+
createNumberProp,
69
} from "@draftbit/types";
710

811
export const SEED_DATA = {
912
name: "Audio Player",
1013
tag: "AudioPlayer",
1114
description: "Given a source URL, plays sounds & audio!",
1215
category: COMPONENT_TYPES.media,
13-
layout: {},
16+
stylesPanelSections: [
17+
StylesPanelSections.Typography,
18+
StylesPanelSections.Background,
19+
StylesPanelSections.Borders,
20+
StylesPanelSections.Size,
21+
StylesPanelSections.MarginsAndPaddings,
22+
StylesPanelSections.Position,
23+
],
24+
layout: {
25+
backgroundColor: "#eee",
26+
paddingLeft: 16,
27+
paddingRight: 16,
28+
paddingTop: 8,
29+
paddingBottom: 8,
30+
borderRadius: 24,
31+
flexDirection: "row",
32+
alignItems: "center",
33+
},
1434
props: {
1535
source: {
1636
group: GROUPS.data,
@@ -23,5 +43,25 @@ export const SEED_DATA = {
2343
formType: FORM_TYPES.sourceUrl,
2444
propType: PROP_TYPES.OBJECT,
2545
},
46+
sliderColor: createColorProp({
47+
label: "Thumb Color",
48+
defaultValue: "strong",
49+
}),
50+
completedTrackColor: createColorProp({
51+
label: "Completed Track Color",
52+
defaultValue: "background",
53+
}),
54+
remainingTrackColor: createColorProp({
55+
label: "Remaining Track Color",
56+
defaultValue: "light",
57+
}),
58+
trackThumbSize: createNumberProp({
59+
label: "Thumb Size",
60+
defaultValue: 24,
61+
}),
62+
playIconColor: createColorProp({
63+
label: "Play Icon Color",
64+
defaultValue: "strong",
65+
}),
2666
},
2767
};

packages/maps/package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,18 @@
4848
"source": "src",
4949
"output": "lib",
5050
"targets": [
51-
"commonjs",
52-
"module",
51+
[
52+
"commonjs",
53+
{
54+
"sourceMaps": false
55+
}
56+
],
57+
[
58+
"module",
59+
{
60+
"sourceMaps": false
61+
}
62+
],
5363
[
5464
"typescript",
5565
{

packages/native/package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,18 @@
5151
"source": "src",
5252
"output": "lib",
5353
"targets": [
54-
"commonjs",
55-
"module",
54+
[
55+
"commonjs",
56+
{
57+
"sourceMaps": false
58+
}
59+
],
60+
[
61+
"module",
62+
{
63+
"sourceMaps": false
64+
}
65+
],
5666
[
5767
"typescript",
5868
{

packages/native/src/components/AudioPlayer.tsx

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
import * as React from "react";
2-
import { Text, View, StyleSheet, TouchableHighlight } from "react-native";
2+
import {
3+
Text,
4+
View,
5+
TouchableHighlight,
6+
StyleProp,
7+
StyleSheet,
8+
} from "react-native";
39
import { Audio, AVPlaybackStatus, AVPlaybackSource } from "expo-av";
410
import { AntDesign } from "@expo/vector-icons";
511
import Slider from "@react-native-community/slider";
612

713
import type { Sound } from "expo-av/build/Audio/Sound";
814

15+
interface Props {
16+
source: AVPlaybackSource;
17+
style?: StyleProp<any>;
18+
sliderColor?: string;
19+
completedTrackColor?: string;
20+
remainingTrackColor?: string;
21+
playSize?: number;
22+
playColor?: string;
23+
}
24+
925
function formatDuration(duration: number) {
1026
if (duration === 0 || duration === 1) return "00:00";
1127

@@ -24,17 +40,59 @@ function formatDuration(duration: number) {
2440
return renderedMinutes + ":" + renderedSeconds;
2541
}
2642

27-
export default function AudioPlayer({ source }: { source: AVPlaybackSource }) {
43+
export default function AudioPlayer({
44+
source,
45+
style = {},
46+
sliderColor = "black",
47+
completedTrackColor = "black",
48+
remainingTrackColor = "black",
49+
playSize = 24,
50+
playColor = "black",
51+
}: Props) {
2852
const [sound, setSound] = React.useState<Sound>();
2953
const [playing, setPlay] = React.useState(false);
3054
const [loading, setLoading] = React.useState(false);
31-
const [durationMillis, setDurationMillis] = React.useState(1);
55+
const [durationMillis, setDurationMillis] = React.useState<
56+
number | undefined
57+
>(1);
3258
const [isDraggingSlider, setIsDraggingSlider] = React.useState(false);
3359
const [sliderPositionMillis, setSliderPositionMillis] = React.useState(0);
3460

61+
const {
62+
color,
63+
fontFamily,
64+
fontWeight,
65+
fontSize,
66+
lineHeight,
67+
letterSpacing,
68+
textTransform,
69+
textAlign,
70+
textDecorationLine,
71+
textDecorationColor,
72+
textDecorationStyle,
73+
...viewStyles
74+
} = StyleSheet.flatten(style || {});
75+
76+
const textStyles = {
77+
color,
78+
fontFamily,
79+
fontWeight,
80+
fontSize,
81+
lineHeight,
82+
letterSpacing,
83+
textTransform,
84+
textAlign,
85+
textDecorationLine,
86+
textDecorationColor,
87+
textDecorationStyle,
88+
};
89+
3590
const onPlaybackStatusUpdate = async (status: AVPlaybackStatus) => {
3691
if (status.isLoaded) {
37-
if (status.isPlaying && !isDraggingSlider) {
92+
if (durationMillis !== status?.durationMillis) {
93+
setDurationMillis(status?.durationMillis || 1);
94+
}
95+
if (status.isPlaying) {
3896
setSliderPositionMillis(status.positionMillis);
3997
}
4098

@@ -120,19 +178,19 @@ export default function AudioPlayer({ source }: { source: AVPlaybackSource }) {
120178
const iconName = loading ? "loading1" : !sound || !playing ? "play" : "pause";
121179

122180
return (
123-
<View style={styles.container}>
181+
<View style={[styles.container, viewStyles]}>
124182
<TouchableHighlight onPress={playSound} style={{ marginRight: 8 }}>
125-
<AntDesign name={iconName} size={24} />
183+
<AntDesign name={iconName} size={playSize} color={playColor} />
126184
</TouchableHighlight>
127-
<Text style={{ marginRight: 8 }}>
128-
{formatDuration(sliderPositionMillis || 0)} /{" "}
185+
<Text style={{ marginRight: 8, ...textStyles }}>
186+
{formatDuration(sliderPositionMillis ?? 0)} /{" "}
129187
{formatDuration(durationMillis || 0)}
130188
</Text>
131189
<Slider
132190
style={{ flex: 1 }}
133-
minimumTrackTintColor="#333"
134-
maximumTrackTintColor="#000000"
135-
thumbTintColor="black"
191+
minimumTrackTintColor={completedTrackColor}
192+
maximumTrackTintColor={remainingTrackColor}
193+
thumbTintColor={sliderColor}
136194
minimumValue={0}
137195
value={sliderPositionMillis}
138196
maximumValue={durationMillis}
@@ -145,10 +203,6 @@ export default function AudioPlayer({ source }: { source: AVPlaybackSource }) {
145203

146204
const styles = StyleSheet.create({
147205
container: {
148-
backgroundColor: "#eee",
149-
paddingHorizontal: 16,
150-
paddingVertical: 8,
151-
borderRadius: 24,
152206
flexDirection: "row",
153207
alignItems: "center",
154208
},

packages/types/package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,18 @@
4040
"source": "src",
4141
"output": "lib",
4242
"targets": [
43-
"commonjs",
44-
"module",
43+
[
44+
"commonjs",
45+
{
46+
"sourceMaps": false
47+
}
48+
],
49+
[
50+
"module",
51+
{
52+
"sourceMaps": false
53+
}
54+
],
4555
[
4656
"typescript",
4757
{

packages/ui/package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,18 @@
5151
"source": "src",
5252
"output": "lib",
5353
"targets": [
54-
"commonjs",
55-
"module",
54+
[
55+
"commonjs",
56+
{
57+
"sourceMaps": false
58+
}
59+
],
60+
[
61+
"module",
62+
{
63+
"sourceMaps": false
64+
}
65+
],
5666
[
5767
"typescript",
5868
{

0 commit comments

Comments
 (0)