This commit is contained in:
Yamozha
2021-04-02 02:24:13 +03:00
parent c23950b545
commit 7256d79e2c
31493 changed files with 3036630 additions and 0 deletions

61
node_modules/expo-linear-gradient/android/build.gradle generated vendored Normal file
View File

@ -0,0 +1,61 @@
apply plugin: 'com.android.library'
apply plugin: 'maven'
group = 'host.exp.exponent'
version = '8.4.0'
// Simple helper that allows the root project to override versions declared by this library.
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
// Upload android library to maven with javadoc and android sources
configurations {
deployerJars
}
// Creating sources with comments
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
// Put the androidSources and javadoc to the artifacts
artifacts {
archives androidSourcesJar
}
uploadArchives {
repositories {
mavenDeployer {
configuration = configurations.deployerJars
repository(url: mavenLocal().url)
}
}
}
android {
compileSdkVersion safeExtGet("compileSdkVersion", 29)
defaultConfig {
minSdkVersion safeExtGet("minSdkVersion", 21)
targetSdkVersion safeExtGet("targetSdkVersion", 29)
versionCode 16
versionName "8.4.0"
}
lintOptions {
abortOnError false
}
}
if (new File(rootProject.projectDir.parentFile, 'package.json').exists()) {
apply from: project(":unimodules-core").file("../unimodules-core.gradle")
} else {
throw new GradleException(
"'unimodules-core.gradle' was not found in the usual React Native dependency location. " +
"This package can only be used in such projects. Are you sure you've installed the dependencies properly?")
}
dependencies {
unimodule "unimodules-core"
}

View File

@ -0,0 +1,5 @@
<manifest package="expo.modules.lineargradient">
</manifest>

View File

@ -0,0 +1,60 @@
package expo.modules.lineargradient;
import android.content.Context;
import org.unimodules.core.ViewManager;
import org.unimodules.core.interfaces.ExpoProp;
import java.util.ArrayList;
public class LinearGradientManager extends ViewManager<LinearGradientView> {
public static final String VIEW_CLASS_NAME = "ExpoLinearGradient";
public static final String PROP_COLORS = "colors";
public static final String PROP_LOCATIONS = "locations";
public static final String PROP_START_POS = "startPoint";
public static final String PROP_END_POS = "endPoint";
public static final String PROP_BORDER_RADII = "borderRadii";
@Override
public String getName() {
return VIEW_CLASS_NAME;
}
@Override
public LinearGradientView createViewInstance(Context context) {
return new LinearGradientView(context);
}
@Override
public ViewManagerType getViewManagerType() {
return ViewManagerType.SIMPLE;
}
@ExpoProp(name = PROP_COLORS)
public void setColors(LinearGradientView view, final ArrayList<Double> colors) {
view.setColors(colors);
}
@ExpoProp(name = PROP_LOCATIONS)
public void setLocations(LinearGradientView view, final ArrayList<Double> locations) {
if (locations != null) {
view.setLocations(locations);
}
}
@ExpoProp(name = PROP_START_POS)
public void setStartPosition(LinearGradientView view, final ArrayList<Double> startPos) {
view.setStartPosition(startPos);
}
@ExpoProp(name = PROP_END_POS)
public void setEndPosition(LinearGradientView view, final ArrayList<Double> endPos) {
view.setEndPosition(endPos);
}
// temporary solution until following issue is resolved:
// https://github.com/facebook/react-native/issues/3198
@ExpoProp(name = PROP_BORDER_RADII)
public void setBorderRadii(LinearGradientView view, final ArrayList<Double> borderRadii) {
view.setBorderRadii(borderRadii);
}
}

View File

@ -0,0 +1,16 @@
package expo.modules.lineargradient;
import android.content.Context;
import java.util.Collections;
import java.util.List;
import org.unimodules.core.BasePackage;
import org.unimodules.core.ViewManager;
public class LinearGradientPackage extends BasePackage {
@Override
public List<ViewManager> createViewManagers(Context context) {
return Collections.singletonList((ViewManager) new LinearGradientManager());
}
}

View File

@ -0,0 +1,128 @@
package expo.modules.lineargradient;
import java.util.ArrayList;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.graphics.Shader;
import android.util.TypedValue;
import android.view.View;
public class LinearGradientView extends View {
private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private Path mPathForBorderRadius;
private RectF mTempRectForBorderRadius;
private float[] mLocations;
private float[] mStartPos = {0, 0};
private float[] mEndPos = {0, 1};
private int[] mColors;
private int[] mSize = {0, 0};
private float[] mBorderRadii = {0, 0, 0, 0, 0, 0, 0, 0};
public LinearGradientView(Context context) {
super(context);
}
public void setStartPosition(final ArrayList<Double> startPos) {
mStartPos = new float[]{startPos.get(0).floatValue(), startPos.get(1).floatValue()};
drawGradient();
}
public void setEndPosition(final ArrayList<Double> endPos) {
mEndPos = new float[]{endPos.get(0).floatValue(), endPos.get(1).floatValue()};
drawGradient();
}
public void setColors(final ArrayList<Double> colors) {
int[] _colors = new int[colors.size()];
for (int i=0; i < _colors.length; i++)
{
_colors[i] = colors.get(i).intValue();
}
mColors = _colors;
drawGradient();
}
public void setLocations(final ArrayList<Double> locations) {
float[] _locations = new float[locations.size()];
for (int i=0; i < _locations.length; i++)
{
_locations[i] = locations.get(i).floatValue();
}
mLocations = _locations;
drawGradient();
}
public void setBorderRadii(final ArrayList<Double> borderRadii) {
float[] _radii = new float[borderRadii.size()];
for (int i=0; i < _radii.length; i++)
{
_radii[i] = toPixelFromDIP(borderRadii.get(i).floatValue());
}
mBorderRadii = _radii;
updatePath();
drawGradient();
}
// Copied from RN PixelUtil
// We might want to expose display metrics on @unimodules/core somewhere to avoid
// having code similar to this littered throughout modules
private float toPixelFromDIP(float value) {
return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
value,
getContext().getResources().getDisplayMetrics()
);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
mSize = new int[]{w, h};
updatePath();
drawGradient();
}
private void drawGradient() {
// guard against crashes happening while multiple properties are updated
if (mColors == null || (mLocations != null && mColors.length != mLocations.length))
return;
LinearGradient mShader = new LinearGradient(
mStartPos[0] * mSize[0],
mStartPos[1] * mSize[1],
mEndPos[0] * mSize[0],
mEndPos[1] * mSize[1],
mColors,
mLocations,
Shader.TileMode.CLAMP);
mPaint.setShader(mShader);
invalidate();
}
private void updatePath() {
if (mPathForBorderRadius == null) {
mPathForBorderRadius = new Path();
mTempRectForBorderRadius = new RectF();
}
mPathForBorderRadius.reset();
mTempRectForBorderRadius.set(0f, 0f, (float) mSize[0], (float) mSize[1]);
mPathForBorderRadius.addRoundRect(
mTempRectForBorderRadius,
mBorderRadii,
Path.Direction.CW);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (mPathForBorderRadius == null) {
canvas.drawPaint(mPaint);
} else {
canvas.drawPath(mPathForBorderRadius, mPaint);
}
}
}