Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}

dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
classpath 'com.android.tools.build:gradle:4.0.1'
}
}

Expand All @@ -28,6 +32,10 @@ android {

repositories {
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
load("//tools/build_defs/oss:rn_defs.bzl", "YOGA_TARGET", "react_native_dep", "react_native_target", "rn_android_library")

rn_android_library(
name = "progressview",
srcs = glob(["*.java"]),
visibility = [
"PUBLIC",
],
deps = [
YOGA_TARGET,
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
react_native_dep("third-party/java/jsr-305:jsr-305"),
react_native_target("java/com/facebook/react/bridge:bridge"),
react_native_target("java/com/facebook/react/common:common"),
react_native_target("java/com/facebook/react/module/annotations:annotations"),
react_native_target("java/com/facebook/react/uimanager:uimanager"),
react_native_target("java/com/facebook/react/uimanager/annotations:annotations"),
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Copyright (c) Facebook, Inc. and its affiliates.

// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

package com.reactnativecommunity.progressview;

import javax.annotation.Nullable;

import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ProgressBar;

import com.facebook.react.bridge.JSApplicationIllegalArgumentException;

/**
* Controls an enclosing ProgressBar. Exists so that the ProgressBar can be recreated if
* the style would change.
*/
/* package */ class RNCProgressViewContainerView extends FrameLayout {
private static final int MAX_PROGRESS = 1000;

private @Nullable Integer mColor;
private boolean mIndeterminate = true;
private boolean mAnimating = true;
private double mProgress;
private @Nullable ProgressBar mProgressBar;

public RNCProgressViewContainerView(Context context) {
super(context);
}

public void setStyle(@Nullable String styleName) {
int style = RNCProgressViewViewManager.getStyleFromString(styleName);
mProgressBar = RNCProgressViewViewManager.createProgressBar(getContext(), style);
mProgressBar.setMax(MAX_PROGRESS);
removeAllViews();
addView(
mProgressBar,
new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
}

public void setColor(@Nullable Integer color) {
this.mColor = color;
}

public void setIndeterminate(boolean indeterminate) {
mIndeterminate = indeterminate;
}

public void setProgress(double progress) {
mProgress = progress;
}

public void setAnimating(boolean animating) {
mAnimating = animating;
}

public void apply() {
if (mProgressBar == null) {
throw new JSApplicationIllegalArgumentException("setStyle() not called");
}

mProgressBar.setIndeterminate(mIndeterminate);
setColor(mProgressBar);
mProgressBar.setProgress((int) (mProgress * MAX_PROGRESS));
if (mAnimating) {
mProgressBar.setVisibility(View.VISIBLE);
} else {
mProgressBar.setVisibility(View.GONE);
}
}

private void setColor(ProgressBar progressBar) {
Drawable drawable;
if (progressBar.isIndeterminate()) {
drawable = progressBar.getIndeterminateDrawable();
} else {
drawable = progressBar.getProgressDrawable();
}

if (drawable == null) {
return;
}

if (mColor != null) {
drawable.setColorFilter(mColor, PorterDuff.Mode.SRC_IN);
} else {
drawable.clearColorFilter();
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@

package com.reactnativecommunity.progressview;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.bridge.JavaScriptModule;

public class RNCProgressViewPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Arrays.<NativeModule>asList(new RNCProgressViewModule(reactContext));
}
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Collections.emptyList();
}

// Deprecated from RN 0.47
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}
// Deprecated from RN 0.47
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}
@Override
@SuppressWarnings("rawtypes")
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.<ViewManager>singletonList(new RNCProgressViewViewManager());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.reactnativecommunity.progressview;

import android.util.SparseIntArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import com.facebook.react.uimanager.LayoutShadowNode;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.yoga.YogaMeasureFunction;
import com.facebook.yoga.YogaMeasureMode;
import com.facebook.yoga.YogaMeasureOutput;
import com.facebook.yoga.YogaNode;
import java.util.HashSet;
import java.util.Set;
import javax.annotation.Nullable;

/**
* Node responsible for holding the style of the ProgressBar, see under
* {@link android.R.attr.progressBarStyle} for possible styles. ReactProgressBarViewManager
* manages how this style is applied to the ProgressBar.
*/
public class RNCProgressViewShadowNode extends LayoutShadowNode implements YogaMeasureFunction {

private String mStyle = RNCProgressViewViewManager.DEFAULT_STYLE;

private final SparseIntArray mHeight;
private final SparseIntArray mWidth;
private final Set<Integer> mMeasured;

public RNCProgressViewShadowNode() {
mHeight = new SparseIntArray();
mWidth = new SparseIntArray();
mMeasured = new HashSet<>();
initMeasureFunction();
}

private void initMeasureFunction() {
setMeasureFunction(this);
}

public @Nullable String getStyle() {
return mStyle;
}

@ReactProp(name = RNCProgressViewViewManager.PROP_STYLE)
public void setStyle(@Nullable String style) {
mStyle = style == null ? RNCProgressViewViewManager.DEFAULT_STYLE : style;
}

@Override
public long measure(
YogaNode node,
float width,
YogaMeasureMode widthMode,
float height,
YogaMeasureMode heightMode) {
final int style = RNCProgressViewViewManager.getStyleFromString(getStyle());
if (!mMeasured.contains(style)) {
ProgressBar progressBar = RNCProgressViewViewManager.createProgressBar(getThemedContext(), style);
final int spec = View.MeasureSpec.makeMeasureSpec(
ViewGroup.LayoutParams.WRAP_CONTENT,
View.MeasureSpec.UNSPECIFIED);
progressBar.measure(spec, spec);
mHeight.put(style, progressBar.getMeasuredHeight());
mWidth.put(style, progressBar.getMeasuredWidth());
mMeasured.add(style);
}

return YogaMeasureOutput.make(mWidth.get(style), mHeight.get(style));
}
}
Loading