Skip to content

Commit

Permalink
feat(android): custom progress color for android
Browse files Browse the repository at this point in the history
  • Loading branch information
4cc3ssX committed Apr 2, 2024
1 parent ba2baaa commit 2dfce8e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions android/src/main/java/com/ting/TingModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Color
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.graphics.drawable.AnimatedVectorDrawable
import android.graphics.drawable.GradientDrawable
import android.os.Handler
Expand Down Expand Up @@ -147,6 +148,7 @@ class TingModule internal constructor(context: ReactApplicationContext) : TingSp
val titleColor = options?.getString("titleColor")
val message = options?.getString("message")
val messageColor = options?.getString("messageColor")
val progressColor = options?.getString("progressColor")
val preset = options?.getString("preset")
val backgroundColor = options?.getString("backgroundColor")
val borderRadius = if (options.hasKey("borderRadius")) options?.getInt("borderRadius") else null
Expand Down Expand Up @@ -213,6 +215,13 @@ class TingModule internal constructor(context: ReactApplicationContext) : TingSp
iconView.visibility = ImageView.GONE
progressBar.id = R.id.loading_spinner
progressBar.layoutParams = progressSize

if (progressColor != null) {
val progressDrawable = progressBar.indeterminateDrawable.mutate()
progressDrawable.colorFilter = PorterDuffColorFilter(parseColor(progressColor), PorterDuff.Mode.SRC_IN)
progressBar.indeterminateDrawable = progressDrawable
}

container.addView(progressBar, 0)
}

Expand Down
2 changes: 2 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ const DATA: ItemType[] = [
title: 'Đáy xã hội',
message: 'Chờ xíu',
preset: 'spinner',
progressColor: '#FD966A',
}),
},
{
Expand Down Expand Up @@ -254,6 +255,7 @@ const DATA: ItemType[] = [
blurBackdrop: 20,
backdropOpacity: 0.1,
preset: 'spinner',
progressColor: '#FD966A',
}),
},
];
Expand Down
12 changes: 12 additions & 0 deletions src/Type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ export interface ToastOptions {
* Defaults to `null`.
*/
icon?: Icon;

/**
* progress color for spinner preset
* @platform android
*/
progressColor?: string;
}

export interface AlertOptions {
Expand Down Expand Up @@ -87,4 +93,10 @@ export interface AlertOptions {
* custom icon
*/
icon?: Icon;

/**
* progress color for spinner preset
* @platform android
*/
progressColor?: string;
}

0 comments on commit 2dfce8e

Please sign in to comment.