|
| 1 | +package com.reactnativecommunity.progressview; |
| 2 | + |
| 3 | +import android.content.res.ColorStateList; |
| 4 | +import android.widget.ProgressBar; |
| 5 | + |
| 6 | +import androidx.annotation.NonNull; |
| 7 | + |
| 8 | +import com.facebook.react.uimanager.SimpleViewManager; |
| 9 | +import com.facebook.react.uimanager.ThemedReactContext; |
| 10 | +import com.facebook.react.uimanager.annotations.ReactProp; |
| 11 | + |
| 12 | +public class RNCProgressViewManager extends SimpleViewManager<ProgressBar> { |
| 13 | + private static final int MAX_PROGRESS_VALUE = 1000; |
| 14 | + |
| 15 | + @NonNull |
| 16 | + @Override |
| 17 | + public String getName() { |
| 18 | + return "RNCProgressView"; |
| 19 | + } |
| 20 | + |
| 21 | + @NonNull |
| 22 | + @Override |
| 23 | + protected ProgressBar createViewInstance(@NonNull ThemedReactContext reactContext) { |
| 24 | + ProgressBar bar = new ProgressBar( |
| 25 | + reactContext, |
| 26 | + null, |
| 27 | + android.R.attr.progressBarStyleHorizontal |
| 28 | + ); |
| 29 | + bar.setMax(MAX_PROGRESS_VALUE); |
| 30 | + return bar; |
| 31 | + } |
| 32 | + |
| 33 | + @ReactProp(name = "progress") |
| 34 | + public void setProgress(ProgressBar bar, double progress) { |
| 35 | + bar.setProgress((int) (MAX_PROGRESS_VALUE * progress)); |
| 36 | + } |
| 37 | + |
| 38 | + @ReactProp(name = "progressTintColor", customType = "Color") |
| 39 | + public void setProgressTintColor(ProgressBar bar, int color) { |
| 40 | + bar.setIndeterminateTintList(ColorStateList.valueOf(color)); |
| 41 | + bar.setProgressTintList(ColorStateList.valueOf(color)); |
| 42 | + } |
| 43 | + |
| 44 | + @ReactProp(name = "trackTintColor", customType = "Color") |
| 45 | + public void setTrackTintColor(ProgressBar bar, int color) { |
| 46 | + bar.setProgressBackgroundTintList(ColorStateList.valueOf(color)); |
| 47 | + } |
| 48 | + |
| 49 | + @ReactProp(name = "isIndeterminate") |
| 50 | + public void setIsIndeterminate(ProgressBar bar, boolean isIndeterminate) { |
| 51 | + bar.setIndeterminate(isIndeterminate); |
| 52 | + } |
| 53 | +} |
0 commit comments