From ee185e15e0e77983d4697c56b9569ca4bd560a6a Mon Sep 17 00:00:00 2001 From: nickY Date: Fri, 24 Apr 2020 05:49:11 +1000 Subject: [PATCH] feat(aws-amplify-react-native): Customise authenticator wrapper component (#5375) * feat(aws-amplify-react-native): enable authenticator wrapper component customization Co-authored-by: Ashish Nanda --- .../aws-amplify-react-native/src/AmplifyUI.js | 6 ++++++ .../src/Auth/Authenticator.js | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/aws-amplify-react-native/src/AmplifyUI.js b/packages/aws-amplify-react-native/src/AmplifyUI.js index 2aa745c69f8..00def9cec08 100644 --- a/packages/aws-amplify-react-native/src/AmplifyUI.js +++ b/packages/aws-amplify-react-native/src/AmplifyUI.js @@ -22,6 +22,7 @@ import { TouchableOpacity, TouchableWithoutFeedback, View, + SafeAreaView, } from 'react-native'; import { I18n } from 'aws-amplify'; import AmplifyTheme, { @@ -33,6 +34,11 @@ import { Icon } from 'react-native-elements'; import countryDialCodes from './CountryDialCodes'; import TEST_ID from './AmplifyTestIDs'; +export const Container = props => { + const theme = props.theme || AmplifyTheme; + return {props.children}; +}; + export const FormField = props => { const theme = props.theme || AmplifyTheme; return ( diff --git a/packages/aws-amplify-react-native/src/Auth/Authenticator.js b/packages/aws-amplify-react-native/src/Auth/Authenticator.js index b8dc66eb454..371578435e6 100644 --- a/packages/aws-amplify-react-native/src/Auth/Authenticator.js +++ b/packages/aws-amplify-react-native/src/Auth/Authenticator.js @@ -12,10 +12,10 @@ */ import React from 'react'; -import { SafeAreaView } from 'react-native'; import { Auth, Analytics, Logger, Hub, JS } from 'aws-amplify'; import AmplifyTheme from '../AmplifyTheme'; import AmplifyMessageMap from '../AmplifyMessageMap'; +import { Container } from '../AmplifyUI'; import Loading from './Loading'; import SignIn from './SignIn'; import ConfirmSignIn from './ConfirmSignIn'; @@ -28,6 +28,10 @@ import Greetings from './Greetings'; const logger = new Logger('Authenticator'); +const EmptyContainer = ({ children }) => ( + {children} +); + class AuthDecorator { constructor(onStateChange) { this.onStateChange = onStateChange; @@ -154,6 +158,13 @@ export default class Authenticator extends React.Component { const { authState, authData } = this.state; const theme = this.props.theme || AmplifyTheme; const messageMap = this.props.errorMessage || AmplifyMessageMap; + // If container prop is undefined, default to AWS Amplify UI Container (SafeAreaView) + // otherwise if truthy, use the supplied render prop + // otherwise if falsey, use EmptyContainer + const ContainerWrapper = + this.props.container === undefined + ? Container + : this.props.container || EmptyContainer; const { hideDefault, signUpConfig, usernameAttributes } = this.props; const props_children = this.props.children || []; @@ -182,6 +193,6 @@ export default class Authenticator extends React.Component { usernameAttributes, }); }); - return {children}; + return {children}; } }