5

为了获得默认的身份验证屏幕,我只能这样做(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。

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

4

4 回答 4

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 />
]);
于 2018-11-02T03:48:32.737 回答
4

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

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

export default class AppWithAuth extends Component {
 render(){
    return (
      <Authenticator>
        <App />
      </Authenticator>
    );
  }
}
于 2018-10-08T22:54:59.453 回答
0

我在为 aws-amplify 自定义注册和登录组件时遇到了同样的问题,所以我创建了这个库(aws-amplify-react-custom-ui)。这是自定义登录的示例:

    import SignIn from "./SignIn";
    import AmplifyCustomUi from "aws-amplify-react-custom-ui";
    AmplifyCustomUi.setSignIn(SignIn);

更多信息: https ://github.com/ysfmag/aws-amplify-react-custom-ui

于 2018-10-21T19:53:40.407 回答
0

是的,我们可以使用 aws-amplify-react-native 包自定义屏幕。使用我们的自定义屏幕调用 Amplify CLI API。逻辑可能因用例而异,这里有一些代码可以帮助您提前请参考此文档

   import React, { Component } from 'react';
    import { View } from 'react-native';
    import {
      Authenticator,
      AmplifyTheme
    } from 'aws-amplify-react-native';
    // Custom  screens
    import Home from './screens/Home';
    import SignIn from './screens/SignIn';
    import SignUp from './screens/SignUp';
    import ConfirmSignUp from './screens/ConfirmSignUp';
    import ForgotPassword from './screens/ForgotPassword';
    //Custom theme
    const theme = {
      ...AmplifyTheme,
      container: {
        flex: 1,
        flexDirection: 'column',
        alignItems: 'center',
        justifyContent: 'space-around',
        paddingTop: 10,
        width: '100%',
        marginTop: 30
      },
    }
    class App extends Component {

      render() {
        return (
          <View style={{ flex: 1 }}>
            <Authenticator theme={theme} hideDefault={true} hide="Home" 
            includeGreetings={true}
            >
              <SignIn />
              <SignUp/>
              <ConfirmSignUp />
              <ForgotPassword />
              <Home />
            </Authenticator>
          </View>
        );
      }
    }

    export default App;

;)

于 2019-05-03T18:55:24.030 回答