首页 > 解决方案 > 是否可以自定义 aws-amplify-react-native 包的默认注册、登录屏幕?

问题描述

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

import { withAuthenticator } from 'aws-amplify-react-native';
export default withAuthenticator(App);

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

然后文档说我不能修改默认值,我必须创建自己的(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。

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

标签: authenticationreact-nativeamazon-cognitoaws-amplify

解决方案


所有 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 />
]);

推荐阅读