import * as React from "react";
import {
Text,
View,
Image,
TextStyle,
ScrollView,
SafeAreaView,
TouchableOpacity,
ViewStyle,
} from "react-native";
/**
* ? Local Imports
*/
import styles from "./SocialLoginScreen.style";
import TextField from "./components/TextField/TextField";
import SocialButton from "./components/SocialButton/SocialButton";
// ? Assets
const backArrowImage = require("./local-assets/left-arrow.png");
const facebookLogo = require("./local-assets/facebook-logo.png");
const twitterLogo = require("./local-assets/twitter-logo.png");
const googleLogo = require("./local-assets/google-logo.png");
const discordLogo = require("./local-assets/discord-logo.png");
const appleLogo = require("./local-assets/apple-logo.png");
export interface ISocialLoginProps {
loginText?: string;
signUpText?: string;
loginTitleText?: string;
forgotPasswordText?: string;
loginButtonShadowColor?: string;
loginButtonBackgroundColor?: string;
usernamePlaceholder?: string;
passwordPlaceholder?: string;
enableAppleLogin?: boolean;
enableFacebookLogin?: boolean;
enableTwitterLogin?: boolean;
enableGoogleLogin?: boolean;
enableDiscordLogin?: boolean;
backArrowImageSource?: any;
loginButtonTextStyle?: any;
usernameTextFieldStyle?: any;
passwordTextFieldStyle?: any;
rightTopAssetImageSource?: any;
leftBottomAssetImageSource?: any;
loginButtonSpinnerVisibility?: boolean;
facebookSpinnerVisibility?: boolean;
discordSpinnerVisibility?: boolean;
twitterSpinnerVisibility?: boolean;
googleSpinnerVisibility?: boolean;
spinnerSize?: number;
spinnerType?: string;
loginButtonSpinnerColor?: string;
facebookSpinnerColor?: string;
twitterSpinnerColor?: string;
googleSpinnerColor?: string;
discordSpinnerColor?: string;
disableSignUp?: boolean;
appleSpinnerColor?: string;
appleSpinnerVisibility?: boolean;
disableForgotButton?: boolean;
loginTextStyle?: TextStyle;
signUpTextStyle?: TextStyle;
forgotPasswordTextStyle?: TextStyle;
onLoginPress: () => void;
onAppleLoginPress?: () => void;
onForgotPasswordPress: () => void;
onFacebookLoginPress?: () => void;
onTwitterLoginPress?: () => void;
onGoogleLoginPress?: () => void;
onDiscordLoginPress?: () => void;
onUserNameChangeText: (text: string) => void;
onPasswordChangeText: (text: string) => void;
//? Only Sign Up Screen Props
onSignUpPress: (isSignUp: boolean) => void;
onRepasswordChangeText?: (text: string) => void;
}
interface IState {
isSignUp: boolean;
}
export default class SocialLoginScreen extends React.PureComponent<
ISocialLoginProps,
IState
> {
constructor(props: ISocialLoginProps) {
super(props);
this.state = {
isSignUp: false,
};
}
renderHeader = () => {
const {
signUpText = "SIGN UP",
disableSignUp,
signUpTextStyle,
backArrowImageSource = backArrowImage,
} = this.props;
return (
!disableSignUp && (
{
this.setState({ isSignUp: !this.state.isSignUp }, () => {
this.props.onSignUpPress &&
this.props.onSignUpPress(this.state.isSignUp);
});
}}
>
{signUpText}
)
);
};
renderLoginTitle = () => {
const { loginTitleText = "Log In", loginTextStyle } = this.props;
return (
{loginTitleText}
);
};
renderTextFieldContainer = () => {
const {
usernameTextFieldStyle,
usernamePlaceholder = "john_doe@example.com",
onUserNameChangeText,
passwordPlaceholder = "• • • • • • • •",
onPasswordChangeText,
passwordTextFieldStyle,
} = this.props;
return (
{this.state.isSignUp
? this.renderRepasswordContainer()
: this.renderForgotPassword()}
);
};
renderRepasswordContainer = () => {
const {
passwordPlaceholder = "• • • • • • • •",
onRepasswordChangeText,
passwordTextFieldStyle,
} = this.props;
return (
);
};
renderForgotPassword = () => {
const {
forgotPasswordText = "Forgot Password?",
forgotPasswordTextStyle,
onForgotPasswordPress,
disableForgotButton,
} = this.props;
return (
!disableForgotButton && (
{forgotPasswordText}
)
);
};
renderClassicLoginButton = () => {
const {
loginText = "Let's cook!",
loginButtonBackgroundColor,
loginButtonShadowColor = "#58a13f",
loginButtonSpinnerVisibility,
spinnerSize,
spinnerType,
loginButtonSpinnerColor,
onLoginPress,
} = this.props;
return (
);
};
renderFacebookLoginButton = () => {
const {
onFacebookLoginPress,
facebookSpinnerVisibility,
spinnerSize,
spinnerType,
facebookSpinnerColor,
} = this.props;
return (
}
onPress={() => onFacebookLoginPress && onFacebookLoginPress()}
/>
);
};
renderAppleLoginButton = () => {
const {
spinnerSize,
spinnerType,
appleSpinnerColor,
onAppleLoginPress,
appleSpinnerVisibility,
} = this.props;
return (
}
onPress={() => onAppleLoginPress && onAppleLoginPress()}
/>
);
};
renderTwitterLoginButton = () => {
const {
onTwitterLoginPress,
twitterSpinnerVisibility,
spinnerSize,
spinnerType,
twitterSpinnerColor,
} = this.props;
return (
}
onPress={() => onTwitterLoginPress && onTwitterLoginPress()}
/>
);
};
renderGoogleLoginButton = () => {
const {
onGoogleLoginPress,
googleSpinnerVisibility,
spinnerSize,
spinnerType,
googleSpinnerColor,
} = this.props;
return (
}
onPress={() => onGoogleLoginPress && onGoogleLoginPress()}
/>
);
};
renderDiscordLoginButton = () => {
const {
spinnerSize,
spinnerType,
discordSpinnerColor,
onDiscordLoginPress,
discordSpinnerVisibility,
} = this.props;
return (
}
onPress={() => onDiscordLoginPress && onDiscordLoginPress()}
/>
);
};
renderSocialButtons = () => {
const {
enableFacebookLogin,
enableTwitterLogin,
enableGoogleLogin,
enableDiscordLogin,
enableAppleLogin,
} = this.props;
return (
{this.renderClassicLoginButton()}
{enableFacebookLogin && this.renderFacebookLoginButton()}
{enableTwitterLogin && this.renderTwitterLoginButton()}
{enableAppleLogin && this.renderAppleLoginButton()}
{enableGoogleLogin && this.renderGoogleLoginButton()}
{enableDiscordLogin && this.renderDiscordLoginButton()}
);
};
renderRightTopAsset = () => {
const { rightTopAssetImageSource } = this.props;
return (
);
};
renderLeftBottomAsset = () => {
const { leftBottomAssetImageSource } = this.props;
return (
);
};
renderContent = () => {
return (
{this.renderHeader()}
{this.renderRightTopAsset()}
{this.renderLoginTitle()}
{this.renderTextFieldContainer()}
{this.renderSocialButtons()}
{this.renderLeftBottomAsset()}
);
};
render() {
return (
{this.renderContent()}
);
}
}