Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Commit

Permalink
fix: children as function for <BluetoothState />
Browse files Browse the repository at this point in the history
  • Loading branch information
patlux committed May 8, 2018
1 parent f2cb31c commit 69ffe96
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 70 deletions.
142 changes: 73 additions & 69 deletions example/app/ExampleWithDeclarativeApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,75 +61,79 @@ class ExampleWithDeclarativeApi extends React.PureComponent {
<AppState onChange={this.onAppStateChange}>
<ListSection title="Example with declarative API">
<BluetoothState onChange={this.onBluetoothStateChange}>
<BluetoothState.PoweredOn>
{({ disable }) => (
<Card>
<CardContent>
<Title>Bluetooth is enabled! :)</Title>
</CardContent>
<CardActions>
{this.state.bluetoothAdminPermission && (
<Button primary onPress={disable}>
Disable
</Button>
)}
</CardActions>
</Card>
)}
</BluetoothState.PoweredOn>
<BluetoothState.PoweredOff>
{({ requestToEnable, openSettings, enable }) => (
<Card>
<CardContent>
<Title>Please enable bluetooth</Title>
{Platform.OS === 'android' &&
this.state.bluetoothAdminPermission && (
<Button raised primary onPress={enable}>
Enable bluetooth
</Button>
)}
{Platform.OS === 'ios' && (
<Button raised primary onPress={openSettings}>
{Platform.Version <= 10 ? 'Open bluetooth settings' : 'Open settings'}
</Button>
)}
{Platform.OS === 'android' && (
<Button raised onPress={openSettings}>
Open settings
</Button>
)}
</CardContent>
</Card>
)}
</BluetoothState.PoweredOff>
<BluetoothState.Resetting>
<Card>
<CardContent>
<ActivityIndicator />
</CardContent>
</Card>
</BluetoothState.Resetting>
<BluetoothState.Unauthorized>
<Card>
<CardContent>
<Text>Please allow us to use bluetooth</Text>
</CardContent>
</Card>
</BluetoothState.Unauthorized>
<BluetoothState.Unsupported>
<Card>
<CardContent>
<Text>Your phone doesn't support bluetooth :(</Text>
</CardContent>
</Card>
</BluetoothState.Unsupported>
<BluetoothState.Unknown>
<Card>
<CardContent>
<Text>You have a really strange phone.</Text>
</CardContent>
</Card>
</BluetoothState.Unknown>
{({ bluetoothState }) => (
<React.Fragment>
<BluetoothState.PoweredOn>
{({ disable }) => (
<Card>
<CardContent>
<Title>Bluetooth is enabled! :)</Title>
</CardContent>
<CardActions>
{this.state.bluetoothAdminPermission && (
<Button primary onPress={disable}>
Disable
</Button>
)}
</CardActions>
</Card>
)}
</BluetoothState.PoweredOn>
<BluetoothState.PoweredOff>
{({ requestToEnable, openSettings, enable }) => (
<Card>
<CardContent>
<Title>Please enable bluetooth</Title>
{Platform.OS === 'android' &&
this.state.bluetoothAdminPermission && (
<Button raised primary onPress={enable}>
Enable bluetooth
</Button>
)}
{Platform.OS === 'ios' && (
<Button raised primary onPress={openSettings}>
{Platform.Version <= 10 ? 'Open bluetooth settings' : 'Open settings'}
</Button>
)}
{Platform.OS === 'android' && (
<Button raised onPress={openSettings}>
Open settings
</Button>
)}
</CardContent>
</Card>
)}
</BluetoothState.PoweredOff>
<BluetoothState.Resetting>
<Card>
<CardContent>
<ActivityIndicator />
</CardContent>
</Card>
</BluetoothState.Resetting>
<BluetoothState.Unauthorized>
<Card>
<CardContent>
<Text>Please allow us to use bluetooth</Text>
</CardContent>
</Card>
</BluetoothState.Unauthorized>
<BluetoothState.Unsupported>
<Card>
<CardContent>
<Text>Your phone doesn't support bluetooth :(</Text>
</CardContent>
</Card>
</BluetoothState.Unsupported>
<BluetoothState.Unknown>
<Card>
<CardContent>
<Text>You have a really strange phone.</Text>
</CardContent>
</Card>
</BluetoothState.Unknown>
</React.Fragment>
)}
</BluetoothState>
</ListSection>
</AppState>
Expand Down
3 changes: 2 additions & 1 deletion src/BluetoothState/BluetoothState.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ class BluetoothStatus extends React.PureComponent {
// RENDER

render() {
const { children } = this.props;
return (
<BluetoothStateContext.Provider value={this.state.context}>
{this.props.children}
{typeof children === 'function' ? children(this.state.context) : children}
</BluetoothStateContext.Provider>
);
}
Expand Down

0 comments on commit 69ffe96

Please sign in to comment.