Skip to content

Commit 12afa86

Browse files
committed
feat: fully customizable AirPlay button
1 parent 85068d7 commit 12afa86

File tree

5 files changed

+33
-22
lines changed

5 files changed

+33
-22
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# react-native-airplay-cast
22

3-
Stream audio or video to AirPlay-enabled devices.
3+
Stream audio or video to AirPlay-enabled devices with a customizable AirPlay button.
44

55
## Installation
66

@@ -13,9 +13,11 @@ npm install react-native-airplay-cast
1313
```js
1414
import { AirPlayButton } from "react-native-airplay-cast";
1515

16-
// ...
17-
18-
<AirPlayButton style={{ width: 30, height: 30 }} />
16+
<AirPlayButton
17+
activeTintColor="blue"
18+
tintColor="black"
19+
style={{ width: 30, height: 30 }}
20+
/>
1921
```
2022

2123
## Contributing

example/src/App.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { AirPlayButton } from 'react-native-airplay-cast';
55
export default function App() {
66
return (
77
<View style={styles.container}>
8-
<AirPlayButton />
8+
<AirPlayButton
9+
activeTintColor="blue"
10+
tintColor="black"
11+
style={styles.button}
12+
/>
913
</View>
1014
);
1115
}
@@ -16,4 +20,8 @@ const styles = StyleSheet.create({
1620
alignItems: 'center',
1721
justifyContent: 'center',
1822
},
23+
button: {
24+
width: 30,
25+
height: 30,
26+
},
1927
});

ios/RNAirPlayButtonManager.m

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#import <React/RCTViewManager.h>
22
#import <Foundation/Foundation.h>
3-
#import <AVFoundation/AVFoundation.h>
4-
#import <MediaPlayer/MediaPlayer.h>
3+
#import <AVKit/AVRoutePickerView.h>
54

65
@interface RNAirPlayButtonManager : RCTViewManager
76
@end
@@ -12,17 +11,11 @@ @implementation RNAirPlayButtonManager
1211

1312
- (UIView *)view
1413
{
15-
if (@available(iOS 11.0, *)) {
16-
AVRoutePickerView *airplayButton = [[AVRoutePickerView alloc] init];
17-
airplayButton.activeTintColor = [UIColor blueColor];
18-
airplayButton.tintColor = [UIColor whiteColor];
19-
return airplayButton;
20-
} else {
21-
// If you still support previous iOS versions, you can use MPVolumeView
22-
MPVolumeView *airplayButton = [[MPVolumeView alloc] init];
23-
airplayButton.showsVolumeSlider = NO;
24-
return airplayButton;
25-
}
14+
AVRoutePickerView *airPlayButton = [[AVRoutePickerView alloc] init];
15+
return airPlayButton;
2616
}
2717

18+
RCT_EXPORT_VIEW_PROPERTY(activeTintColor, UIColor);
19+
RCT_EXPORT_VIEW_PROPERTY(tintColor, UIColor);
20+
2821
@end

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-native-airplay-cast",
3-
"version": "0.1.0",
4-
"description": "Stream audio or video to AirPlay-enabled devices",
3+
"version": "1.0.0",
4+
"description": "Stream audio or video to AirPlay-enabled devices with a customizable AirPlay button",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",
77
"types": "lib/typescript/src/index.d.ts",

src/index.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
import { requireNativeComponent } from 'react-native';
1+
import { requireNativeComponent, ViewProps } from 'react-native';
22

33
// type AirPlayCastType = {
44
// };
55

66
// const { AirPlayCast } = NativeModules;
77

8-
export const AirPlayButton = requireNativeComponent('RNAirPlayButton');
8+
type AirPlayButtonProps = ViewProps & {
9+
activeTintColor?: string;
10+
tintColor?: string;
11+
style?: React.CSSProperties;
12+
};
13+
14+
export const AirPlayButton = requireNativeComponent<AirPlayButtonProps>(
15+
'RNAirPlayButton'
16+
);
917

1018
// export default AirPlayCast as AirPlayCastType;

0 commit comments

Comments
 (0)