From c8a04c3d28701ad202c8f582cdbc3706ee6c5d83 Mon Sep 17 00:00:00 2001 From: Horcrux Date: Tue, 19 Apr 2016 15:18:16 +0800 Subject: [PATCH] remove unused vars --- .gitignore | 41 ++++- Example/android/app/build.gradle | 14 +- Example/android/app/proguard-rules.pro | 4 +- Example/android/app/react.gradle | 140 ++++++++---------- .../java/com/artsvgexample/MainActivity.java | 3 +- Example/examples/Line.js | 1 + Example/package.json | 2 +- README.md | 2 + elements/Circle.js | 1 - elements/Ellipse.js | 7 +- elements/Line.js | 35 ++++- elements/Stop.js | 6 +- elements/Svg.js | 9 +- elements/Symbol.js | 3 +- elements/Use.js | 1 - elements/ViewBox.js | 7 +- lib/fillFilter.js | 1 - 17 files changed, 162 insertions(+), 115 deletions(-) diff --git a/.gitignore b/.gitignore index 78f2710d..a1b7fbca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,41 @@ -node_modules/ +# OSX +# +.DS_Store + +# Xcode +# +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +project.xcworkspace + +# Android/IJ +# .idea/ +.gradle +local.properties + +# node.js +# +node_modules/ +npm-debug.log + + +# webstorm +# +android/app/src/main/assets/index.android.bundle +ios/marry/assets +ios/marry/main.jsbundle +*.iml diff --git a/Example/android/app/build.gradle b/Example/android/app/build.gradle index a824b87f..74b52283 100644 --- a/Example/android/app/build.gradle +++ b/Example/android/app/build.gradle @@ -3,7 +3,8 @@ apply plugin: "com.android.application" import com.android.build.OutputFile /** - * The react.gradle file registers two tasks: bundleDebugJsAndAssets and bundleReleaseJsAndAssets. + * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets + * and bundleReleaseJsAndAssets). * These basically call `react-native bundle` with the correct arguments during the Android build * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the * bundle directly from the development server. Below you can see all the possible configurations @@ -23,6 +24,13 @@ import com.android.build.OutputFile * // whether to bundle JS and assets in release mode * bundleInRelease: true, * + * // whether to bundle JS and assets in another build variant (if configured). + * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants + * // The configuration property is in the format 'bundleIn${productFlavor}${buildType}' + * // bundleInFreeDebug: true, + * // bundleInPaidRelease: true, + * // bundleInBeta: true, + * * // the root of your project, i.e. where "package.json" lives * root: "../../", * @@ -84,7 +92,7 @@ android { splits { abi { enable enableSeparateBuildPerCPUArchitecture - universalApk true + universalApk false reset() include "armeabi-v7a", "x86" } @@ -113,5 +121,5 @@ android { dependencies { compile fileTree(dir: "libs", include: ["*.jar"]) compile "com.android.support:appcompat-v7:23.0.1" - compile "com.facebook.react:react-native:0.18.+" + compile "com.facebook.react:react-native:0.20.+" } diff --git a/Example/android/app/proguard-rules.pro b/Example/android/app/proguard-rules.pro index 35840261..7d72e469 100644 --- a/Example/android/app/proguard-rules.pro +++ b/Example/android/app/proguard-rules.pro @@ -42,8 +42,8 @@ -keep class * extends com.facebook.react.bridge.NativeModule { *; } -keepclassmembers,includedescriptorclasses class * { native ; } -keepclassmembers class * { @com.facebook.react.uimanager.UIProp ; } --keepclassmembers class * { @com.facebook.react.uimanager.ReactProp ; } --keepclassmembers class * { @com.facebook.react.uimanager.ReactPropGroup ; } +-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp ; } +-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup ; } -dontwarn com.facebook.react.** diff --git a/Example/android/app/react.gradle b/Example/android/app/react.gradle index f2152d1f..4b43bf91 100644 --- a/Example/android/app/react.gradle +++ b/Example/android/app/react.gradle @@ -11,69 +11,8 @@ def elvisFile(thing) { } def reactRoot = elvisFile(config.root) ?: file("../../") -def jsBundleDirDebug = elvisFile(config.jsBundleDirDebug) ?: - file("$buildDir/intermediates/assets/debug") -def jsBundleDirRelease = elvisFile(config.jsBundleDirRelease) ?: - file("$buildDir/intermediates/assets/release") -def resourcesDirDebug = elvisFile(config.resourcesDirDebug) ?: - file("$buildDir/intermediates/res/merged/debug") -def resourcesDirRelease = elvisFile(config.resourcesDirRelease) ?: - file("$buildDir/intermediates/res/merged/release") def inputExcludes = config.inputExcludes ?: ["android/**", "ios/**"] -def jsBundleFileDebug = file("$jsBundleDirDebug/$bundleAssetName") -def jsBundleFileRelease = file("$jsBundleDirRelease/$bundleAssetName") - -task bundleDebugJsAndAssets(type: Exec) { - // create dirs if they are not there (e.g. the "clean" task just ran) - doFirst { - jsBundleDirDebug.mkdirs() - resourcesDirDebug.mkdirs() - } - - // set up inputs and outputs so gradle can cache the result - inputs.files fileTree(dir: reactRoot, excludes: inputExcludes) - outputs.dir jsBundleDirDebug - outputs.dir resourcesDirDebug - - // set up the call to the react-native cli - workingDir reactRoot - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine "cmd", "/c", "react-native", "bundle", "--platform", "android", "--dev", "true", "--entry-file", - entryFile, "--bundle-output", jsBundleFileDebug, "--assets-dest", resourcesDirDebug - } else { - commandLine "react-native", "bundle", "--platform", "android", "--dev", "true", "--entry-file", - entryFile, "--bundle-output", jsBundleFileDebug, "--assets-dest", resourcesDirDebug - } - - enabled config.bundleInDebug ?: false -} - -task bundleReleaseJsAndAssets(type: Exec) { - // create dirs if they are not there (e.g. the "clean" task just ran) - doFirst { - jsBundleDirRelease.mkdirs() - resourcesDirRelease.mkdirs() - } - - // set up inputs and outputs so gradle can cache the result - inputs.files fileTree(dir: reactRoot, excludes: inputExcludes) - outputs.dir jsBundleDirRelease - outputs.dir resourcesDirRelease - - // set up the call to the react-native cli - workingDir reactRoot - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine "cmd","/c", "react-native", "bundle", "--platform", "android", "--dev", "false", "--entry-file", - entryFile, "--bundle-output", jsBundleFileRelease, "--assets-dest", resourcesDirRelease - } else { - commandLine "react-native", "bundle", "--platform", "android", "--dev", "false", "--entry-file", - entryFile, "--bundle-output", jsBundleFileRelease, "--assets-dest", resourcesDirRelease - } - - enabled config.bundleInRelease ?: true -} - void runBefore(String dependentTaskName, Task task) { Task dependentTask = tasks.findByPath(dependentTaskName); if (dependentTask != null) { @@ -82,25 +21,76 @@ void runBefore(String dependentTaskName, Task task) { } gradle.projectsEvaluated { + // Grab all build types and product flavors + def buildTypes = android.buildTypes.collect { type -> type.name } + def productFlavors = android.productFlavors.collect { flavor -> flavor.name } - // hook bundleDebugJsAndAssets into the android build process + // When no product flavors defined, use empty + if (!productFlavors) productFlavors.add('') - bundleDebugJsAndAssets.dependsOn mergeDebugResources - bundleDebugJsAndAssets.dependsOn mergeDebugAssets + productFlavors.each { productFlavorName -> + buildTypes.each { buildTypeName -> + // Create variant and source names + def sourceName = "${buildTypeName}" + def targetName = "${sourceName.capitalize()}" + if (productFlavorName) { + sourceName = "${productFlavorName}${targetName}" + } - runBefore('processArmeabi-v7aDebugResources', bundleDebugJsAndAssets) - runBefore('processX86DebugResources', bundleDebugJsAndAssets) - runBefore('processUniversalDebugResources', bundleDebugJsAndAssets) - runBefore('processDebugResources', bundleDebugJsAndAssets) + // React js bundle directories + def jsBundleDirConfigName = "jsBundleDir${targetName}" + def jsBundleDir = elvisFile(config."$jsBundleDirConfigName") ?: + file("$buildDir/intermediates/assets/${sourceName}") - // hook bundleReleaseJsAndAssets into the android build process + def resourcesDirConfigName = "jsBundleDir${targetName}" + def resourcesDir = elvisFile(config."${resourcesDirConfigName}") ?: + file("$buildDir/intermediates/res/merged/${sourceName}") + def jsBundleFile = file("$jsBundleDir/$bundleAssetName") - bundleReleaseJsAndAssets.dependsOn mergeReleaseResources - bundleReleaseJsAndAssets.dependsOn mergeReleaseAssets + // Bundle task name for variant + def bundleJsAndAssetsTaskName = "bundle${targetName}JsAndAssets" - runBefore('processArmeabi-v7aReleaseResources', bundleReleaseJsAndAssets) - runBefore('processX86ReleaseResources', bundleReleaseJsAndAssets) - runBefore('processUniversalReleaseResources', bundleReleaseJsAndAssets) - runBefore('processReleaseResources', bundleReleaseJsAndAssets) + def currentBundleTask = tasks.create( + name: bundleJsAndAssetsTaskName, + type: Exec) { + group = "react" + description = "bundle JS and assets for ${targetName}." + // Create dirs if they are not there (e.g. the "clean" task just ran) + doFirst { + jsBundleDir.mkdirs() + resourcesDir.mkdirs() + } + + // Set up inputs and outputs so gradle can cache the result + inputs.files fileTree(dir: reactRoot, excludes: inputExcludes) + outputs.dir jsBundleDir + outputs.dir resourcesDir + + // Set up the call to the react-native cli + workingDir reactRoot + + // Set up dev mode + def devEnabled = !targetName.toLowerCase().contains("release") + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine "cmd", "/c", "react-native", "bundle", "--platform", "android", "--dev", "${devEnabled}", + "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir + } else { + commandLine "react-native", "bundle", "--platform", "android", "--dev", "${devEnabled}", + "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir + } + + enabled config."bundleIn${targetName}" ?: targetName.toLowerCase().contains("release") + } + + // Hook bundle${productFlavor}${buildType}JsAndAssets into the android build process + currentBundleTask.dependsOn("merge${targetName}Resources") + currentBundleTask.dependsOn("merge${targetName}Assets") + + runBefore("processArmeabi-v7a${targetName}Resources", currentBundleTask) + runBefore("processX86${targetName}Resources", currentBundleTask) + runBefore("processUniversal${targetName}Resources", currentBundleTask) + runBefore("process${targetName}Resources", currentBundleTask) + } + } } diff --git a/Example/android/app/src/main/java/com/artsvgexample/MainActivity.java b/Example/android/app/src/main/java/com/artsvgexample/MainActivity.java index 97bf956c..e2950901 100644 --- a/Example/android/app/src/main/java/com/artsvgexample/MainActivity.java +++ b/Example/android/app/src/main/java/com/artsvgexample/MainActivity.java @@ -34,6 +34,7 @@ public class MainActivity extends ReactActivity { @Override protected List getPackages() { return Arrays.asList( - new MainReactPackage()); + new MainReactPackage() + ); } } diff --git a/Example/examples/Line.js b/Example/examples/Line.js index 812c161c..b7cd7752 100644 --- a/Example/examples/Line.js +++ b/Example/examples/Line.js @@ -8,6 +8,7 @@ import Svg, { class LineExample extends Component{ static title = 'Line'; + render() { return { + return `M${props.x1},${props.y1}L${props.x2},${props.y2}Z`; + }; + + setNativeProps = (props) => { + let nativeProps = {}; + if (props.x1 || props.x2 || props.y1 || props.y2) { + let path = this._convertPath(Object.assign({}, this.props, props)); + nativeProps.d = new Path(path).toJSON(); + } else if (props.strokeLinecap || props.strokeCap) { + // TODO: + } + + this.refs.shape.setNativeProps(nativeProps); + }; + + render() { return ; } } diff --git a/elements/Stop.js b/elements/Stop.js index 0903d179..8a56dd56 100644 --- a/elements/Stop.js +++ b/elements/Stop.js @@ -1,11 +1,7 @@ import React, { Component, - PropTypes, - ART + PropTypes } from 'react-native'; -let { - Group -} = ART; class Stop extends Component{ static displayName = 'Stop'; static propTypes = { diff --git a/elements/Svg.js b/elements/Svg.js index 4a0045ec..f1300a91 100644 --- a/elements/Svg.js +++ b/elements/Svg.js @@ -1,16 +1,16 @@ import React, { - ART, Component, PropTypes, Children, - cloneElement + cloneElement, + ART } from 'react-native'; import extractViewbox from '../lib/extractViewbox'; import ViewBox from './ViewBox'; import _ from 'lodash'; + let { - Surface, - Group + Surface } = ART; let id = 0; @@ -54,6 +54,7 @@ class Svg extends Component{ return