是否可以自定义 aws-amplify-react-native 包的默认注册、登录屏幕?

Gre*_*een 4 authentication amazon-cognito react-native aws-amplify

为了拥有默认的身份验证屏幕,我只能这样做(https://github.com/aws-samples/aws-mobile-react-native-starter):

import { withAuthenticator } from 'aws-amplify-react-native';
export default withAuthenticator(App);
Run Code Online (Sandbox Code Playgroud)

我得到了非常丑陋的默认开箱即用登录屏幕:

然后文档说我不能修改默认值,我必须创建自己的(https://github.com/aws-samples/aws-mobile-react-native-starter):

您可以使用此高阶组件,也可以构建自己的 UI 并使用 Amplify 的 API。

但他们也说,我可以自定义默认登录屏幕(https://github.com/aws/aws-amplify/blob/master/README.md):

AWS Amplify 将为您提供用于常见用例(例如用户注册和登录)的可自定义 UI。

问题是,我们可以自定义默认屏幕,还是如果我们想要一些奇特的东西就必须创建自己的屏幕?

C.L*_*Lee 8

所有 Amplify Authenticator 组件都可以从 aws-amplify-react-native 单独导入。您可以repo ( https://github.com/aws-amplify/amplify-js/tree/master/packages/aws-amplify-react-native/src )的源代码复制到您自己的项目中,修改并导入从那里。* 如果您想获取其他框架的包 - React、Vue、Angular 等,请访问这里https://github.com/aws-amplify/amplify-js/tree/master/packages/aws-amplify-react-原生的

目前,在我的项目中,我正在自定义SignUp, SignIn and ConfigrmSignUp组件,如下所示。这是创建您自己的 UI 的建议方法,它可以与放大验证器无缝协作。

在此处查看更多信息:https : //aws-amplify.github.io/docs/js/authentication#create-your-own-ui

import {
  withAuthenticator,
  SignUp,
  ConfirmSignIn,
  ConfirmSignUp,
  ForgotPassword,
  VerifyContact,
  Greetings,
  Loading,
  RequireNewPassword
} from 'aws-amplify-react-native';

import { 
  Authenticator, 
  ConfirmSignUpScreen, <----- customized authenticator component
  SignUpScreen, <----- customized authenticator component
  SignInScreen <----- customized authenticator component
} from './screens/auth';

export default withAuthenticator(App, false, [
  <Loading />
  <SignInScreen />  <----- customized authenticator component
  <ConfirmSignIn />  
  <VerifyContact />
  <SignUpScreen />  <----- customized authenticator component
  <ConfirmSignUpScreen />  <----- customized authenticator component
  <ForgotPassword />
  <RequireNewPassword />
  <Greetings />
]);
Run Code Online (Sandbox Code Playgroud)


And*_*ser 4

根据文档,您应该能够将您的应用程序包装在 HOC( Authenticator) 中,而不是使用withAuthenticator.

import { Authenticator } from 'aws-amplify-react';

export default class AppWithAuth extends Component {
 render(){
    return (
      <Authenticator>
        <App />
      </Authenticator>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)