-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Android support for progress-view (#58)
Co-authored-by: Alpha <[email protected]>
- Loading branch information
1 parent
3dd6cab
commit af6c3e7
Showing
17 changed files
with
114 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
android/src/main/java/com/reactnativecommunity/progressview/RNCProgressViewManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.reactnativecommunity.progressview; | ||
|
||
import android.content.res.ColorStateList; | ||
import android.widget.ProgressBar; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.facebook.react.uimanager.SimpleViewManager; | ||
import com.facebook.react.uimanager.ThemedReactContext; | ||
import com.facebook.react.uimanager.annotations.ReactProp; | ||
|
||
public class RNCProgressViewManager extends SimpleViewManager<ProgressBar> { | ||
private static final int MAX_PROGRESS_VALUE = 1000; | ||
|
||
@NonNull | ||
@Override | ||
public String getName() { | ||
return "RNCProgressView"; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
protected ProgressBar createViewInstance(@NonNull ThemedReactContext reactContext) { | ||
ProgressBar bar = new ProgressBar( | ||
reactContext, | ||
null, | ||
android.R.attr.progressBarStyleHorizontal | ||
); | ||
bar.setMax(MAX_PROGRESS_VALUE); | ||
return bar; | ||
} | ||
|
||
@ReactProp(name = "progress") | ||
public void setProgress(ProgressBar bar, double progress) { | ||
bar.setProgress((int) (MAX_PROGRESS_VALUE * progress)); | ||
} | ||
|
||
@ReactProp(name = "progressTintColor", customType = "Color") | ||
public void setProgressTintColor(ProgressBar bar, int color) { | ||
bar.setIndeterminateTintList(ColorStateList.valueOf(color)); | ||
bar.setProgressTintList(ColorStateList.valueOf(color)); | ||
} | ||
|
||
@ReactProp(name = "trackTintColor", customType = "Color") | ||
public void setTrackTintColor(ProgressBar bar, int color) { | ||
bar.setProgressBackgroundTintList(ColorStateList.valueOf(color)); | ||
} | ||
|
||
@ReactProp(name = "isIndeterminate") | ||
public void setIsIndeterminate(ProgressBar bar, boolean isIndeterminate) { | ||
bar.setIndeterminate(isIndeterminate); | ||
} | ||
} |
22 changes: 0 additions & 22 deletions
22
android/src/main/java/com/reactnativecommunity/progressview/RNCProgressViewModule.java
This file was deleted.
Oops, something went wrong.
27 changes: 12 additions & 15 deletions
27
android/src/main/java/com/reactnativecommunity/progressview/RNCProgressViewPackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,25 @@ | ||
|
||
package com.reactnativecommunity.progressview; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import androidx.annotation.NonNull; | ||
|
||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.uimanager.ViewManager; | ||
import com.facebook.react.bridge.JavaScriptModule; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class RNCProgressViewPackage implements ReactPackage { | ||
@NonNull | ||
@Override | ||
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) { | ||
return Arrays.<NativeModule>asList(new RNCProgressViewModule(reactContext)); | ||
} | ||
|
||
// Deprecated from RN 0.47 | ||
public List<Class<? extends JavaScriptModule>> createJSModules() { | ||
return Collections.emptyList(); | ||
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) { | ||
return Collections.emptyList(); | ||
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) { | ||
return Collections.<ViewManager>singletonList(new RNCProgressViewManager()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
rootProject.name = 'example' | ||
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) | ||
include ':app' | ||
|
||
include ':progressview' | ||
project(':progressview').projectDir = new File(rootProject.projectDir, '../../android') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters