Skip to content

Commit

Permalink
feat: fully customizable AirPlay button
Browse files Browse the repository at this point in the history
  • Loading branch information
dylancom committed Oct 13, 2020
1 parent 85068d7 commit 12afa86
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# react-native-airplay-cast

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

## Installation

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

// ...

<AirPlayButton style={{ width: 30, height: 30 }} />
<AirPlayButton
activeTintColor="blue"
tintColor="black"
style={{ width: 30, height: 30 }}
/>
```

## Contributing
Expand Down
10 changes: 9 additions & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { AirPlayButton } from 'react-native-airplay-cast';
export default function App() {
return (
<View style={styles.container}>
<AirPlayButton />
<AirPlayButton
activeTintColor="blue"
tintColor="black"
style={styles.button}
/>
</View>
);
}
Expand All @@ -16,4 +20,8 @@ const styles = StyleSheet.create({
alignItems: 'center',
justifyContent: 'center',
},
button: {
width: 30,
height: 30,
},
});
19 changes: 6 additions & 13 deletions ios/RNAirPlayButtonManager.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#import <React/RCTViewManager.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>
#import <AVKit/AVRoutePickerView.h>

@interface RNAirPlayButtonManager : RCTViewManager
@end
Expand All @@ -12,17 +11,11 @@ @implementation RNAirPlayButtonManager

- (UIView *)view
{
if (@available(iOS 11.0, *)) {
AVRoutePickerView *airplayButton = [[AVRoutePickerView alloc] init];
airplayButton.activeTintColor = [UIColor blueColor];
airplayButton.tintColor = [UIColor whiteColor];
return airplayButton;
} else {
// If you still support previous iOS versions, you can use MPVolumeView
MPVolumeView *airplayButton = [[MPVolumeView alloc] init];
airplayButton.showsVolumeSlider = NO;
return airplayButton;
}
AVRoutePickerView *airPlayButton = [[AVRoutePickerView alloc] init];
return airPlayButton;
}

RCT_EXPORT_VIEW_PROPERTY(activeTintColor, UIColor);
RCT_EXPORT_VIEW_PROPERTY(tintColor, UIColor);

@end
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-native-airplay-cast",
"version": "0.1.0",
"description": "Stream audio or video to AirPlay-enabled devices",
"version": "1.0.0",
"description": "Stream audio or video to AirPlay-enabled devices with a customizable AirPlay button",
"main": "lib/commonjs/index",
"module": "lib/module/index",
"types": "lib/typescript/src/index.d.ts",
Expand Down
12 changes: 10 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { requireNativeComponent } from 'react-native';
import { requireNativeComponent, ViewProps } from 'react-native';

// type AirPlayCastType = {
// };

// const { AirPlayCast } = NativeModules;

export const AirPlayButton = requireNativeComponent('RNAirPlayButton');
type AirPlayButtonProps = ViewProps & {
activeTintColor?: string;
tintColor?: string;
style?: React.CSSProperties;
};

export const AirPlayButton = requireNativeComponent<AirPlayButtonProps>(
'RNAirPlayButton'
);

// export default AirPlayCast as AirPlayCastType;

0 comments on commit 12afa86

Please sign in to comment.