Skip to content

Commit

Permalink
fix(android): add isSupported check, API19+ required (#137)
Browse files Browse the repository at this point in the history
* Exclude okhttp from flipper-network-plugin in example

Okhttp requires android 5+, see: facebook/flipper#1037

* Implemented isSupported check for Android
  • Loading branch information
dburdan authored Sep 12, 2020
1 parent 822b689 commit d3b2f99
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 104 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,19 @@ import { View } from 'react-native';
import { AppleButton } from '@invertase/react-native-apple-authentication';

async function onAppleButtonPress() {

}

// Apple authentication requires API 19+, so we check before showing the login button
function App() {
return (
<View>
<AppleButton
buttonStyle={AppleButton.Style.WHITE}
buttonType={AppleButton.Type.SIGN_IN}
onPress={() => onAppleButtonPress()}
/>
{appleAuthAndroid.isSupported && (
<AppleButton
buttonStyle={AppleButton.Style.WHITE}
buttonType={AppleButton.Type.SIGN_IN}
onPress={() => onAppleButtonPress()}
/>
)}
</View>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.RNAppleAuthentication;

import android.app.Activity;
import android.os.Build;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -74,6 +75,7 @@ public Map<String, Object> getConstants() {

constants.put("ResponseType", ResponseType);
constants.put("Scope", Scope);
constants.put("isSupported", Build.VERSION.SDK_INT >= 19);

return constants;
}
Expand Down
21 changes: 16 additions & 5 deletions docs/interfaces/_lib_index_d_.appleauthandroid.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,30 @@

## Properties

### isSupported

**isSupported**: *boolean*

*Defined in [lib/index.d.ts:572](../../lib/index.d.ts#L572)*

A boolean value of whether Apple Authentication is supported on this API version.
The Apple authentication process requires API 19+ to work correctly.

___

### Error

**Error**: *[AndroidError](../modules/_lib_index_d_.md#androiderror)*

*Defined in [lib/index.d.ts:579](../../lib/index.d.ts#L579)*
*Defined in [lib/index.d.ts:586](../../lib/index.d.ts#L586)*

___

### ResponseType

**ResponseType**: *typeof AndroidResponseType*

*Defined in [lib/index.d.ts:590](../../lib/index.d.ts#L590)*
*Defined in [lib/index.d.ts:597](../../lib/index.d.ts#L597)*

The type of response requested. Valid values are `code` and `id_token`. You can request one or both.

Expand All @@ -42,7 +53,7 @@ ___

**Scope**: *typeof AndroidScope*

*Defined in [lib/index.d.ts:585](../../lib/index.d.ts#L585)*
*Defined in [lib/index.d.ts:592](../../lib/index.d.ts#L592)*

The amount of user information requested from Apple. Valid values are `name` and `email`.
You can request one, both, or none.
Expand All @@ -53,7 +64,7 @@ You can request one, both, or none.

**configure**(`configObject`: [AndroidConfig](_lib_index_d_.androidconfig.md)): *void*

*Defined in [lib/index.d.ts:572](../../lib/index.d.ts#L572)*
*Defined in [lib/index.d.ts:579](../../lib/index.d.ts#L579)*

Prepare the module for sign in. This *must* be called before `appleAuthAndroid.signIn()`;

Expand All @@ -73,7 +84,7 @@ ___

**signIn**(): *Promise‹[AndroidSigninResponse](_lib_index_d_.androidsigninresponse.md)*

*Defined in [lib/index.d.ts:577](../../lib/index.d.ts#L577)*
*Defined in [lib/index.d.ts:584](../../lib/index.d.ts#L584)*

Open browser window to begin user sign in. *Must* call `appleAuthAndroid.configure(options)` first.

Expand Down
1 change: 1 addition & 0 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ dependencies {
}
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
exclude group:'com.squareup.okhttp3', module:'okhttp'
}
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
Expand Down
168 changes: 88 additions & 80 deletions example/app.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,89 +98,97 @@ export default RootComponent = () => {

return (
<View style={[styles.container, styles.horizontal]}>
<Text style={styles.header}>Buttons</Text>

<Text style={{ marginBottom: 8 }}>Continue Styles</Text>
<AppleButton
style={{ marginBottom: 10 }}
cornerRadius={5}
buttonStyle={AppleButton.Style.WHITE}
buttonType={AppleButton.Type.CONTINUE}
onPress={() => doAppleLogin()}
leftView={(
<Image
style={{
alignSelf: 'center',
width: 14,
height: 14,
marginRight: 7,
resizeMode: 'contain',
}}
source={appleLogoBlack}
{appleAuthAndroid.isSupported && (
<View>
<Text style={styles.header}>Buttons</Text>

<Text style={{ marginBottom: 8 }}>Continue Styles</Text>
<AppleButton
style={{ marginBottom: 10 }}
cornerRadius={5}
buttonStyle={AppleButton.Style.WHITE}
buttonType={AppleButton.Type.CONTINUE}
onPress={() => doAppleLogin()}
leftView={(
<Image
style={{
alignSelf: 'center',
width: 14,
height: 14,
marginRight: 7,
resizeMode: 'contain',
}}
source={appleLogoBlack}
/>
)}
/>
<AppleButton
style={{ marginBottom: 10 }}
cornerRadius={0}
buttonStyle={AppleButton.Style.WHITE_OUTLINE}
buttonType={AppleButton.Type.CONTINUE}
onPress={() => doAppleLogin()}
leftView={(
<Image
style={{
alignSelf: 'center',
width: 14,
height: 14,
marginRight: 7,
resizeMode: 'contain',
}}
source={appleLogoBlack}
/>
)}
/>
<AppleButton
style={{ marginBottom: 16 }}
cornerRadius={30}
buttonStyle={AppleButton.Style.BLACK}
buttonType={AppleButton.Type.CONTINUE}
onPress={() => doAppleLogin()}
leftView={(
<Image
style={{
alignSelf: 'center',
width: 14,
height: 14,
marginRight: 7,
resizeMode: 'contain',
}}
source={appleLogoWhite}
/>
)}
/>
)}
/>
<AppleButton
style={{ marginBottom: 10 }}
cornerRadius={0}
buttonStyle={AppleButton.Style.WHITE_OUTLINE}
buttonType={AppleButton.Type.CONTINUE}
onPress={() => doAppleLogin()}
leftView={(
<Image
style={{
alignSelf: 'center',
width: 14,
height: 14,
marginRight: 7,
resizeMode: 'contain',
}}
source={appleLogoBlack}

<Text style={{ marginBottom: 8 }}>Sign-in Styles</Text>
<AppleButton
style={{ marginBottom: 10 }}
cornerRadius={5}
buttonStyle={AppleButton.Style.WHITE}
buttonType={AppleButton.Type.SIGN_IN}
onPress={() => doAppleLogin()}
/>
<AppleButton
style={{ marginBottom: 10 }}
cornerRadius={5}
buttonStyle={AppleButton.Style.WHITE_OUTLINE}
buttonType={AppleButton.Type.SIGN_IN}
onPress={() => doAppleLogin()}
/>
)}
/>
<AppleButton
style={{ marginBottom: 16 }}
cornerRadius={30}
buttonStyle={AppleButton.Style.BLACK}
buttonType={AppleButton.Type.CONTINUE}
onPress={() => doAppleLogin()}
leftView={(
<Image
style={{
alignSelf: 'center',
width: 14,
height: 14,
marginRight: 7,
resizeMode: 'contain',
}}
source={appleLogoWhite}
<AppleButton
style={{ marginBottom: 10 }}
cornerRadius={5}
buttonStyle={AppleButton.Style.BLACK}
buttonType={AppleButton.Type.SIGN_IN}
onPress={() => doAppleLogin()}
/>
)}
/>

<Text style={{ marginBottom: 8 }}>Sign-in Styles</Text>
<AppleButton
style={{ marginBottom: 10 }}
cornerRadius={5}
buttonStyle={AppleButton.Style.WHITE}
buttonType={AppleButton.Type.SIGN_IN}
onPress={() => doAppleLogin()}
/>
<AppleButton
style={{ marginBottom: 10 }}
cornerRadius={5}
buttonStyle={AppleButton.Style.WHITE_OUTLINE}
buttonType={AppleButton.Type.SIGN_IN}
onPress={() => doAppleLogin()}
/>
<AppleButton
style={{ marginBottom: 10 }}
cornerRadius={5}
buttonStyle={AppleButton.Style.BLACK}
buttonType={AppleButton.Type.SIGN_IN}
onPress={() => doAppleLogin()}
/>
</View>
)}

{!appleAuthAndroid.isSupported && (
<Text>Sign In with Apple requires Android 4.4 (API 19) or higher.</Text>
)}
</View>
);
}
Expand Down
7 changes: 7 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,13 @@ interface AndroidSigninResponse {
}

interface AppleAuthAndroid {
/**
* A boolean value of whether Apple Authentication is supported on this API version.
*
* The Apple authentication process requires API 19+ to work correctly.
*/
isSupported: boolean;

/**
* Prepare the module for sign in. This *must* be called before `appleAuthAndroid.signIn()`;
*
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default appleAuth;
* Android
*/
export const appleAuthAndroid = RNAppleAuthModuleAndroid ? {
isSupported: RNAppleAuthModuleAndroid.isSupported,
configure: RNAppleAuthModuleAndroid.configure,
signIn: RNAppleAuthModuleAndroid.signIn,

Expand Down
28 changes: 15 additions & 13 deletions type-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,21 @@ function App() {
buttonType={AppleButton.Type.SIGN_IN}
onPress={() => onAppleButtonPress()}
/>
<AppleButton
cornerRadius={5}
buttonStyle={AppleButton.Style.WHITE}
buttonType={AppleButton.Type.CONTINUE}
onPress={() => onAppleButtonPressAndroid()}
style={{
width: 200,
}}
textStyle={{
fontSize: 14,
}}
leftView={<View />}
/>
{appleAuthAndroid.isSupported && (
<AppleButton
cornerRadius={5}
buttonStyle={AppleButton.Style.WHITE}
buttonType={AppleButton.Type.CONTINUE}
onPress={() => onAppleButtonPressAndroid()}
style={{
width: 200,
}}
textStyle={{
fontSize: 14,
}}
leftView={<View />}
/>
)}
</View>
);
}
Expand Down

0 comments on commit d3b2f99

Please sign in to comment.