Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize default TouchID dialog #263

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
43 changes: 19 additions & 24 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,38 +1,32 @@
// Inspired by rayronvictor's PR #248 tp react-native-config
// https://github.com/luggit/react-native-config/pull/248

def _ext = rootProject.ext
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

buildscript {
repositories {
maven {
url 'https://maven.google.com/'
name 'Google'
// The Android Gradle plugin is only required when opening the android folder stand-alone.
// This avoids unnecessary downloads and potential conflicts when the library is included as a
// module dependency in an application project.
if (project == rootProject) {
repositories {
google()
jcenter()
}
jcenter()
google()
}

dependencies {
classpath _ext.has('gradleBuildTools') ? _ext.gradleBuildTools : 'com.android.tools.build:gradle:3.4.0'
dependencies {
classpath("com.android.tools.build:gradle:3.4.1")
}
}
}

apply plugin: 'com.android.library'

def _reactNativeVersion = _ext.has('reactNative') ? _ext.reactNative : '+'
def _compileSdkVersion = _ext.has('compileSdkVersion') ? _ext.compileSdkVersion : 27
def _buildToolsVersion = _ext.has('buildToolsVersion') ? _ext.buildToolsVersion : '27.0.3'
def _minSdkVersion = _ext.has('minSdkVersion') ? _ext.minSdkVersion : 16
def _targetSdkVersion = _ext.has('targetSdkVersion') ? _ext.targetSdkVersion : 27

android {
compileSdkVersion _compileSdkVersion
buildToolsVersion _buildToolsVersion
compileSdkVersion safeExtGet('compileSdkVersion', 28)
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')

defaultConfig {
minSdkVersion _minSdkVersion
targetSdkVersion _targetSdkVersion
minSdkVersion safeExtGet('minSdkVersion', 16)
targetSdkVersion safeExtGet('targetSdkVersion', 28)
versionCode 1
versionName "1.0"
}
Expand All @@ -43,8 +37,9 @@ android {

repositories {
mavenCentral()
jcenter()
}

dependencies {
implementation "com.facebook.react:react-native:${_reactNativeVersion}"
implementation "com.facebook.react:react-native:0.60.6"
}
19 changes: 13 additions & 6 deletions android/src/main/java/com/rnfingerprint/FingerprintDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class FingerprintDialog extends DialogFragment implements FingerprintHand
private String cancelText = "";
private String sensorDescription = "";
private String sensorErrorDescription = "";
private String sensorTitle = "";
private String errorText = "";

@Override
Expand All @@ -45,7 +46,7 @@ public void onAttach(Context context) {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Material_Light_Dialog);
setStyle(DialogFragment.STYLE_NO_TITLE, 0);
setCancelable(false);
}

Expand All @@ -56,6 +57,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
final TextView mFingerprintDescription = (TextView) v.findViewById(R.id.fingerprint_description);
mFingerprintDescription.setText(this.authReason);

final TextView mFingerprintTitle = (TextView) v.findViewById(R.id.fingerprint_title);
mFingerprintTitle.setText(this.sensorTitle);

this.mFingerprintImage = (ImageView) v.findViewById(R.id.fingerprint_icon);
if (this.imageColor != 0) {
this.mFingerprintImage.setColorFilter(this.imageColor);
Expand All @@ -67,16 +71,15 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
this.mFingerprintError = (TextView) v.findViewById(R.id.fingerprint_error);
this.mFingerprintError.setText(this.errorText);

final Button mCancelButton = (Button) v.findViewById(R.id.cancel_button);
mCancelButton.setText(this.cancelText);
mCancelButton.setOnClickListener(new View.OnClickListener() {
final TextView mSkip = (TextView) v.findViewById(R.id.skip);
mSkip.setText(this.cancelText);
mSkip.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onCancelled();
}
});

getDialog().setTitle(this.dialogTitle);
getDialog().setOnKeyListener(new DialogInterface.OnKeyListener() {
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if (keyCode != KeyEvent.KEYCODE_BACK || mFingerprintHandler == null) {
Expand Down Expand Up @@ -153,6 +156,10 @@ public void setAuthConfig(final ReadableMap config) {
if (config.hasKey("imageErrorColor")) {
this.imageErrorColor = config.getInt("imageErrorColor");
}

if (config.hasKey("sensorTitle")) {
this.sensorTitle = config.getString("sensorTitle");
}
}

public interface DialogResultListener {
Expand All @@ -172,7 +179,7 @@ public void onAuthenticated() {

@Override
public void onError(String errorString, int errorCode) {
this.mFingerprintError.setText(errorString);
this.mFingerprintError.setText("Try again");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should coming from a strings file

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure i will update. Thanks @rolandolopez

this.mFingerprintImage.setColorFilter(this.imageErrorColor);
this.mFingerprintSensorDescription.setText(this.sensorErrorDescription);
}
Expand Down
Binary file added android/src/main/res/font/montserratbold.ttf
Binary file not shown.
Binary file added android/src/main/res/font/montserratlight.ttf
Binary file not shown.
Binary file added android/src/main/res/font/montserratmedium.ttf
Binary file not shown.
Binary file not shown.
Binary file added android/src/main/res/font/montserratregular.ttf
Binary file not shown.
Binary file added android/src/main/res/font/montserratsemibold.ttf
Binary file not shown.
131 changes: 69 additions & 62 deletions android/src/main/res/layout/fingerprint_dialog.xml
Original file line number Diff line number Diff line change
@@ -1,79 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fingerprint_container"
android:layout_width="match_parent"
android:layout_width="250dp"
android:bottomLeftRadius="30dp"
android:bottomRightRadius="30dp"
android:topLeftRadius="30dp"
android:topRightRadius="10dp"
android:layout_height="match_parent"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:paddingLeft="30dp"
android:paddingRight="30dp"
Comment on lines +5 to +14

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should all be in dimens files

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure i will update. Thanks @rolandolopez

android:orientation="vertical"
android:weightSum="1">

android:background="#0c2646">
<!-- https://medium.com/@chrisbanes/appcompat-v23-2-age-of-the-vectors-91cbafa87c88#.btn3al2l2 appCompat works if app is srcCompat 7 activity-->
<!-- app:srcCompat="@drawable/ic_fp_40px" -->

<TextView
android:id="@+id/fingerprint_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="10dp"
android:gravity="left"
android:text="TextView"
android:textColor="#696969"
android:textSize="17dp" />


<LinearLayout
android:layout_width="fill_parent"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:paddingBottom="25dp"
android:paddingRight="20dp"
android:paddingTop="25dp">

android:orientation="vertical"
android:layout_centerVertical="true"
android:paddingTop="15dp"
android:paddingBottom="15dp">
<TextView
android:id="@+id/fingerprint_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#c2cee1"
android:letterSpacing="0.02"
android:lineSpacingExtra="6sp"
android:fontFamily="@font/montserratregular"
android:layout_gravity="center"
android:text="Enable Fingerprint" />
<TextView
android:id="@+id/fingerprint_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textColor="#33599c"
android:letterSpacing="0.03"
android:lineSpacingExtra="4sp"
android:layout_marginTop="5dp"
android:fontFamily="@font/montserratregular"
android:layout_gravity="center"
android:text="For faster and secure login" />
<ImageView
android:id="@+id/fingerprint_icon"
android:layout_width="65dp"
android:layout_height="65dp"
android:layout_marginLeft="25dp"
android:gravity="left"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginTop="20dp"
android:layout_gravity="center"
android:src="@drawable/ic_fp_40px" />

<TextView
android:id="@+id/fingerprint_sensor_description"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:gravity="left|center_vertical"
android:text="Touch sensor"
android:layout_gravity="center"
android:textColor="#696969"
android:textSize="15dp" />
android:textSize="15dp"
android:visibility="gone" />
<TextView
android:id="@+id/fingerprint_error"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#db695e"
android:textSize="15dp"
android:fontFamily="@font/montserratregular"
android:lineSpacingExtra="0.4dp" />
<TextView
android:id="@+id/skip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_marginTop="25dp"
android:textColor="#738ab7"
android:letterSpacing="0.03"
android:lineSpacingExtra="12sp"
android:fontFamily="@font/montserratregular"
android:layout_gravity="center"
android:text="SKIP" />
</LinearLayout>

<TextView
android:id="@+id/fingerprint_error"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp"
android:gravity="center"
android:text="TextView"
android:textColor="#F00"
android:textSize="15dp" />

<Button
android:id="@+id/cancel_button"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:paddingRight="15dp"
android:paddingLeft="15dp"
android:layout_marginEnd="10dp"
android:background="#fff"
android:text="Cancel"
android:textColor="#696969" />

</LinearLayout>
</RelativeLayout>