diff --git a/examples/AccordionExample/.buckconfig b/examples/AccordionExample/.buckconfig new file mode 100644 index 0000000..934256c --- /dev/null +++ b/examples/AccordionExample/.buckconfig @@ -0,0 +1,6 @@ + +[android] + target = Google Inc.:Google APIs:23 + +[maven_repositories] + central = https://repo1.maven.org/maven2 diff --git a/examples/AccordionExample/.flowconfig b/examples/AccordionExample/.flowconfig index 245c23a..466bb11 100644 --- a/examples/AccordionExample/.flowconfig +++ b/examples/AccordionExample/.flowconfig @@ -15,11 +15,6 @@ # Ignore react and fbjs where there are overlaps, but don't ignore # anything that react-native relies on .*/node_modules/fbjs/lib/Map.js -.*/node_modules/fbjs/lib/Promise.js -.*/node_modules/fbjs/lib/fetch.js -.*/node_modules/fbjs/lib/ExecutionEnvironment.js -.*/node_modules/fbjs/lib/isEmpty.js -.*/node_modules/fbjs/lib/crc32.js .*/node_modules/fbjs/lib/ErrorUtils.js # Flow has a built-in definition for the 'react' module which we prefer to use @@ -28,6 +23,11 @@ .*/node_modules/react/lib/React.js .*/node_modules/react/lib/ReactDOM.js +.*/__mocks__/.* +.*/__tests__/.* + +.*/commoner/test/source/widget/share.js + # Ignore commoner tests .*/node_modules/commoner/test/.* @@ -40,26 +40,60 @@ # Ignore Website .*/website/.* +# Ignore generators +.*/local-cli/generator.* + +# Ignore BUCK generated folders +.*\.buckd/ + +# Ignore RNPM +.*/local-cli/rnpm/.* + +.*/node_modules/is-my-json-valid/test/.*\.json +.*/node_modules/iconv-lite/encodings/tables/.*\.json +.*/node_modules/y18n/test/.*\.json +.*/node_modules/spdx-license-ids/spdx-license-ids.json +.*/node_modules/spdx-exceptions/index.json +.*/node_modules/resolve/test/subdirs/node_modules/a/b/c/x.json +.*/node_modules/resolve/lib/core.json +.*/node_modules/jsonparse/samplejson/.*\.json +.*/node_modules/json5/test/.*\.json +.*/node_modules/ua-parser-js/test/.*\.json +.*/node_modules/builtin-modules/builtin-modules.json +.*/node_modules/binary-extensions/binary-extensions.json +.*/node_modules/url-regex/tlds.json +.*/node_modules/joi/.*\.json +.*/node_modules/isemail/.*\.json +.*/node_modules/tr46/.*\.json + + [include] [libs] node_modules/react-native/Libraries/react-native/react-native-interface.js +node_modules/react-native/flow +flow/ [options] module.system=haste +esproposal.class_static_fields=enable +esproposal.class_instance_fields=enable + +experimental.strict_type_args=true + munge_underscores=true module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub' -module.name_mapper='^[./a-zA-Z0-9$_-]+\.png$' -> 'RelativeImageStub' +module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' suppress_type=$FlowIssue suppress_type=$FlowFixMe suppress_type=$FixMe -suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(2[0-0]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) -suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(2[0-0]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ +suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(2[0-6]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) +suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(2[0-6]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy [version] -0.20.1 +^0.26.0 diff --git a/examples/AccordionExample/.gitignore b/examples/AccordionExample/.gitignore index 94fc867..eb1535e 100644 --- a/examples/AccordionExample/.gitignore +++ b/examples/AccordionExample/.gitignore @@ -24,6 +24,7 @@ project.xcworkspace # Android/IJ # +*.iml .idea .gradle local.properties @@ -32,3 +33,9 @@ local.properties # node_modules/ npm-debug.log + +# BUCK +buck-out/ +\.buckd/ +android/app/libs +android/keystores/debug.keystore diff --git a/examples/AccordionExample/AccordionList.js b/examples/AccordionExample/AccordionList.js new file mode 100644 index 0000000..83d276d --- /dev/null +++ b/examples/AccordionExample/AccordionList.js @@ -0,0 +1,80 @@ +'use strict'; + +import React from 'react' + +import { + ListView, + Text, + TouchableHighlight, + View +} from 'react-native'; + +import Accordion from 'react-native-accordion'; +import { range } from 'lodash'; + +const AccordionList = React.createClass({ + getInitialState() { + const ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 }); + return { + dataSource: ds.cloneWithRows(range(20)), + }; + }, + + render() { + return ( + + + + ); + }, + + _renderHeader() { + return ( + + Click to Expand + + ); + }, + + _renderContent() { + return ( + + + This content is hidden in the accordion + + + ); + }, + + _renderRow(rowData) { + return ( + + ); + } +}); + +module.exports = AccordionList; diff --git a/examples/AccordionExample/android/app/BUCK b/examples/AccordionExample/android/app/BUCK new file mode 100644 index 0000000..de28f20 --- /dev/null +++ b/examples/AccordionExample/android/app/BUCK @@ -0,0 +1,66 @@ +import re + +# To learn about Buck see [Docs](https://buckbuild.com/). +# To run your application with Buck: +# - install Buck +# - `npm start` - to start the packager +# - `cd android` +# - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US` +# - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck +# - `buck install -r android/app` - compile, install and run application +# + +lib_deps = [] +for jarfile in glob(['libs/*.jar']): + name = 'jars__' + re.sub(r'^.*/([^/]+)\.jar$', r'\1', jarfile) + lib_deps.append(':' + name) + prebuilt_jar( + name = name, + binary_jar = jarfile, + ) + +for aarfile in glob(['libs/*.aar']): + name = 'aars__' + re.sub(r'^.*/([^/]+)\.aar$', r'\1', aarfile) + lib_deps.append(':' + name) + android_prebuilt_aar( + name = name, + aar = aarfile, + ) + +android_library( + name = 'all-libs', + exported_deps = lib_deps +) + +android_library( + name = 'app-code', + srcs = glob([ + 'src/main/java/**/*.java', + ]), + deps = [ + ':all-libs', + ':build_config', + ':res', + ], +) + +android_build_config( + name = 'build_config', + package = 'com.accordionexample', +) + +android_resource( + name = 'res', + res = 'src/main/res', + package = 'com.accordionexample', +) + +android_binary( + name = 'app', + package_type = 'debug', + manifest = 'src/main/AndroidManifest.xml', + keystore = '//android/keystores:debug', + deps = [ + ':app-code', + ], +) diff --git a/examples/AccordionExample/android/app/build.gradle b/examples/AccordionExample/android/app/build.gradle index d69cdb7..95f62ed 100644 --- a/examples/AccordionExample/android/app/build.gradle +++ b/examples/AccordionExample/android/app/build.gradle @@ -1,12 +1,15 @@ 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 * and their defaults. If you decide to add a configuration block, make sure to add it before the - * `apply from: "react.gradle"` line. + * `apply from: "../../node_modules/react-native/react.gradle"` line. * * project.ext.react = [ * // the name of the generated asset file containing your JS bundle @@ -21,6 +24,15 @@ apply plugin: "com.android.application" * // 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 can be in the following formats + * // 'bundleIn${productFlavor}${buildType}' + * // 'bundleIn${buildType}' + * // bundleInFreeDebug: true, + * // bundleInPaidRelease: true, + * // bundleInBeta: true, + * * // the root of your project, i.e. where "package.json" lives * root: "../../", * @@ -43,11 +55,32 @@ apply plugin: "com.android.application" * // date; if you have any other folders that you want to ignore for performance reasons (gradle * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ * // for example, you might want to remove it from here. - * inputExcludes: ["android/**", "ios/**"] + * inputExcludes: ["android/**", "ios/**"], + * + * // override which node gets called and with what additional arguments + * nodeExecutableAndArgs: ["node"] + * + * // supply additional arguments to the packager + * extraPackagerArgs: [] * ] */ -apply from: "react.gradle" +apply from: "../../node_modules/react-native/react.gradle" + +/** + * Set this to true to create two separate APKs instead of one: + * - An APK that only works on ARM devices + * - An APK that only works on x86 devices + * The advantage is the size of the APK is reduced by about 4MB. + * Upload all the APKs to the Play Store and people will download + * the correct one based on the CPU architecture of their device. + */ +def enableSeparateBuildPerCPUArchitecture = false + +/** + * Run Proguard to shrink the Java bytecode in release builds. + */ +def enableProguardInReleaseBuilds = false android { compileSdkVersion 23 @@ -63,16 +96,44 @@ android { abiFilters "armeabi-v7a", "x86" } } + splits { + abi { + reset() + enable enableSeparateBuildPerCPUArchitecture + universalApk false // If true, also generate a universal APK + include "armeabi-v7a", "x86" + } + } buildTypes { release { - minifyEnabled false // Set this to true to enable Proguard + minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" } } + // applicationVariants are e.g. debug, release + applicationVariants.all { variant -> + variant.outputs.each { output -> + // For each separate APK per architecture, set a unique version code as described here: + // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits + def versionCodes = ["armeabi-v7a":1, "x86":2] + def abi = output.getFilter(OutputFile.ABI) + if (abi != null) { // null for the universal-debug, universal-release variants + output.versionCodeOverride = + versionCodes.get(abi) * 1048576 + defaultConfig.versionCode + } + } + } } 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:+" // From node_modules +} + +// Run this once to be able to run the application with BUCK +// puts all compile dependencies into folder libs for BUCK to use +task copyDownloadableDepsToLibs(type: Copy) { + from configurations.compile + into 'libs' } diff --git a/examples/AccordionExample/android/app/proguard-rules.pro b/examples/AccordionExample/android/app/proguard-rules.pro index ffa8c9f..48361a9 100644 --- a/examples/AccordionExample/android/app/proguard-rules.pro +++ b/examples/AccordionExample/android/app/proguard-rules.pro @@ -26,11 +26,14 @@ # See http://sourceforge.net/p/proguard/bugs/466/ -keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip -keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters +-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip # Do not strip any method/class that is annotated with @DoNotStrip -keep @com.facebook.proguard.annotations.DoNotStrip class * +-keep @com.facebook.common.internal.DoNotStrip class * -keepclassmembers class * { @com.facebook.proguard.annotations.DoNotStrip *; + @com.facebook.common.internal.DoNotStrip *; } -keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * { @@ -40,17 +43,20 @@ -keep class * extends com.facebook.react.bridge.JavaScriptModule { *; } -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.** # okhttp -keepattributes Signature -keepattributes *Annotation* --keep class com.squareup.okhttp.** { *; } --keep interface com.squareup.okhttp.** { *; } --dontwarn com.squareup.okhttp.** +-keep class okhttp3.** { *; } +-keep interface okhttp3.** { *; } +-dontwarn okhttp3.** # okio diff --git a/examples/AccordionExample/android/app/react.gradle b/examples/AccordionExample/android/app/react.gradle index 1e08b00..850e40d 100644 --- a/examples/AccordionExample/android/app/react.gradle +++ b/examples/AccordionExample/android/app/react.gradle @@ -11,77 +11,87 @@ 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() +void runBefore(String dependentTaskName, Task task) { + Task dependentTask = tasks.findByPath(dependentTaskName); + if (dependentTask != null) { + dependentTask.dependsOn task } +} - // 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 - } +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 } - enabled config.bundleInDebug ?: false -} + // When no product flavors defined, use empty + if (!productFlavors) productFlavors.add('') -task bundleReleaseJsAndAssets(type: Exec) { - // create dirs if they are not there (e.g. the "clean" task just ran) - doFirst { - jsBundleDirRelease.mkdirs() - resourcesDirRelease.mkdirs() - } + productFlavors.each { productFlavorName -> + buildTypes.each { buildTypeName -> + // Create variant and target names + def targetName = "${productFlavorName.capitalize()}${buildTypeName.capitalize()}" + def targetPath = productFlavorName ? + "${productFlavorName}/${buildTypeName}" : + "${buildTypeName}" - // 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 - } + // React js bundle directories + def jsBundleDirConfigName = "jsBundleDir${targetName}" + def jsBundleDir = elvisFile(config."$jsBundleDirConfigName") ?: + file("$buildDir/intermediates/assets/${targetPath}") - enabled config.bundleInRelease ?: true -} + def resourcesDirConfigName = "resourcesDir${targetName}" + def resourcesDir = elvisFile(config."${resourcesDirConfigName}") ?: + file("$buildDir/intermediates/res/merged/${targetPath}") + def jsBundleFile = file("$jsBundleDir/$bundleAssetName") -gradle.projectsEvaluated { - // hook bundleDebugJsAndAssets into the android build process - bundleDebugJsAndAssets.dependsOn mergeDebugResources - bundleDebugJsAndAssets.dependsOn mergeDebugAssets - processDebugResources.dependsOn bundleDebugJsAndAssets - - // hook bundleReleaseJsAndAssets into the android build process - bundleReleaseJsAndAssets.dependsOn mergeReleaseResources - bundleReleaseJsAndAssets.dependsOn mergeReleaseAssets - processReleaseResources.dependsOn bundleReleaseJsAndAssets + // Bundle task name for variant + def bundleJsAndAssetsTaskName = "bundle${targetName}JsAndAssets" + + 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", "node", "node_modules/react-native/local-cli/cli.js", "bundle", "--platform", "android", "--dev", "${devEnabled}", + "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir + } else { + commandLine "node", "node_modules/react-native/local-cli/cli.js", "bundle", "--platform", "android", "--dev", "${devEnabled}", + "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir + } + + enabled config."bundleIn${targetName}" || + config."bundleIn${buildTypeName.capitalize()}" ?: + 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/examples/AccordionExample/android/app/src/main/java/com/accordionexample/MainActivity.java b/examples/AccordionExample/android/app/src/main/java/com/accordionexample/MainActivity.java index 2656a7e..a876393 100644 --- a/examples/AccordionExample/android/app/src/main/java/com/accordionexample/MainActivity.java +++ b/examples/AccordionExample/android/app/src/main/java/com/accordionexample/MainActivity.java @@ -27,13 +27,14 @@ protected boolean getUseDeveloperSupport() { return BuildConfig.DEBUG; } - /** - * A list of packages used by the app. If the app uses additional views - * or modules besides the default ones, add more packages here. - */ + /** + * A list of packages used by the app. If the app uses additional views + * or modules besides the default ones, add more packages here. + */ @Override protected List getPackages() { - return Arrays.asList( - new MainReactPackage()); + return Arrays.asList( + new MainReactPackage() + ); } } diff --git a/examples/AccordionExample/android/build.gradle b/examples/AccordionExample/android/build.gradle index ccdfc4e..fcba4c5 100644 --- a/examples/AccordionExample/android/build.gradle +++ b/examples/AccordionExample/android/build.gradle @@ -16,5 +16,9 @@ allprojects { repositories { mavenLocal() jcenter() + maven { + // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm + url "$rootDir/../node_modules/react-native/android" + } } } diff --git a/examples/AccordionExample/index.android.js b/examples/AccordionExample/index.android.js index 9c4d189..00020d5 100644 --- a/examples/AccordionExample/index.android.js +++ b/examples/AccordionExample/index.android.js @@ -1,51 +1,15 @@ -/** - * Sample React Native App - * https://github.com/facebook/react-native - */ 'use strict'; -import React, { - AppRegistry, - Component, - StyleSheet, - Text, - View +import React, {Component} from 'react'; +import { + AppRegistry } from 'react-native'; +import AccordionList from './AccordionList'; + class AccordionExample extends Component { render() { - return ( - - - Welcome to React Native! - - - To get started, edit index.android.js - - - Shake or press menu button for dev menu - - - ); + return ; } } -const styles = StyleSheet.create({ - container: { - flex: 1, - justifyContent: 'center', - alignItems: 'center', - backgroundColor: '#F5FCFF', - }, - welcome: { - fontSize: 20, - textAlign: 'center', - margin: 10, - }, - instructions: { - textAlign: 'center', - color: '#333333', - marginBottom: 5, - }, -}); - AppRegistry.registerComponent('AccordionExample', () => AccordionExample); diff --git a/examples/AccordionExample/index.ios.js b/examples/AccordionExample/index.ios.js index 0a7d93e..42efcf5 100644 --- a/examples/AccordionExample/index.ios.js +++ b/examples/AccordionExample/index.ios.js @@ -2,17 +2,11 @@ import React, { Component } from 'react'; import { AppRegistry, - ListView, NavigatorIOS, - ScrollView, - StatusBarIOS, - StyleSheet, - Text, - TouchableHighlight, - View + StatusBarIOS } from 'react-native'; -import Accordion from 'react-native-accordion'; -import { range } from 'lodash'; + +import AccordionList from './AccordionList'; class AccordionExample extends Component { componentDidMount() { @@ -34,88 +28,4 @@ class AccordionExample extends Component { } } -const AccordionList = React.createClass({ - getInitialState() { - const ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 }); - return { - dataSource: ds.cloneWithRows(range(20)), - }; - }, - - render() { - return ( - - - - ); - }, - - _renderHeader() { - return ( - - Click to Expand - - ); - }, - - _renderContent() { - return ( - - - This content is hidden in the accordion - - - ); - }, - - _renderRow(rowData) { - return ( - - ); - } -}); - -const styles = StyleSheet.create({ - container: { - flex: 1, - justifyContent: 'center', - alignItems: 'center', - backgroundColor: '#F5FCFF' - }, - welcome: { - fontSize: 20, - textAlign: 'center', - margin: 10 - }, - instructions: { - textAlign: 'center', - color: '#333333', - marginBottom: 5 - } -}); - AppRegistry.registerComponent('AccordionExample', () => AccordionExample); diff --git a/examples/AccordionExample/ios/AccordionExample.xcodeproj/project.pbxproj b/examples/AccordionExample/ios/AccordionExample.xcodeproj/project.pbxproj index 3101e3c..fbd77fe 100644 --- a/examples/AccordionExample/ios/AccordionExample.xcodeproj/project.pbxproj +++ b/examples/AccordionExample/ios/AccordionExample.xcodeproj/project.pbxproj @@ -20,6 +20,7 @@ 13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB11A68108700A75B9A /* LaunchScreen.xib */; }; 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; + 140ED2AC1D01E1AD002B40FF /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; }; 146834051AC3E58100842450 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; }; 832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; }; /* End PBXBuildFile section */ @@ -133,6 +134,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 140ED2AC1D01E1AD002B40FF /* libReact.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -525,7 +527,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "../node_modules/react-native/packager/react-native-xcode.sh"; + shellScript = "export NODE_BINARY=node\n../node_modules/react-native/packager/react-native-xcode.sh"; showEnvVarsInLog = 1; }; /* End PBXShellScriptBuildPhase section */ @@ -575,10 +577,6 @@ isa = XCBuildConfiguration; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - ); GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", @@ -596,10 +594,6 @@ buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; COPY_PHASE_STRIP = NO; - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - ); INFOPLIST_FILE = AccordionExampleTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.2; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -620,7 +614,10 @@ ); INFOPLIST_FILE = "AccordionExample/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - OTHER_LDFLAGS = "-ObjC"; + OTHER_LDFLAGS = ( + "-ObjC", + "-lc++", + ); PRODUCT_NAME = AccordionExample; }; name = Debug; @@ -636,7 +633,10 @@ ); INFOPLIST_FILE = "AccordionExample/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - OTHER_LDFLAGS = "-ObjC"; + OTHER_LDFLAGS = ( + "-ObjC", + "-lc++", + ); PRODUCT_NAME = AccordionExample; }; name = Release; diff --git a/examples/AccordionExample/ios/AccordionExample/AppDelegate.m b/examples/AccordionExample/ios/AccordionExample/AppDelegate.m index 96eb605..4c139d3 100644 --- a/examples/AccordionExample/ios/AccordionExample/AppDelegate.m +++ b/examples/AccordionExample/ios/AccordionExample/AppDelegate.m @@ -36,7 +36,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( /** * OPTION 2 * Load from pre-bundled file on disk. The static bundle is automatically - * generated by "Bundle React Native code and images" build step. + * generated by the "Bundle React Native code and images" build step when + * running the project on an actual device or running the project on the + * simulator in the "Release" build configuration. */ // jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; @@ -45,6 +47,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( moduleName:@"AccordionExample" initialProperties:nil launchOptions:launchOptions]; + rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; UIViewController *rootViewController = [UIViewController new]; diff --git a/examples/AccordionExample/ios/AccordionExample/Info.plist b/examples/AccordionExample/ios/AccordionExample/Info.plist index 91963b2..e98ebb0 100644 --- a/examples/AccordionExample/ios/AccordionExample/Info.plist +++ b/examples/AccordionExample/ios/AccordionExample/Info.plist @@ -38,11 +38,17 @@ NSLocationWhenInUseUsageDescription - NSAppTransportSecurity - - - NSAllowsArbitraryLoads - - + NSAppTransportSecurity + + + NSExceptionDomains + + localhost + + NSTemporaryExceptionAllowsInsecureHTTPLoads + + + + diff --git a/examples/AccordionExample/ios/AccordionExampleTests/AccordionExampleTests.m b/examples/AccordionExample/ios/AccordionExampleTests/AccordionExampleTests.m index bc4028a..8acdf2d 100644 --- a/examples/AccordionExample/ios/AccordionExampleTests/AccordionExampleTests.m +++ b/examples/AccordionExample/ios/AccordionExampleTests/AccordionExampleTests.m @@ -13,7 +13,7 @@ #import "RCTLog.h" #import "RCTRootView.h" -#define TIMEOUT_SECONDS 240 +#define TIMEOUT_SECONDS 600 #define TEXT_TO_LOOK_FOR @"Welcome to React Native!" @interface AccordionExampleTests : XCTestCase diff --git a/index.ios.js b/index.js similarity index 100% rename from index.ios.js rename to index.js diff --git a/package.json b/package.json index 9d2a8be..0f20277 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "react-native-accordion", "version": "1.0.0", "description": "An Accordion Component for React Native", - "main": "index.ios.js", + "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, diff --git a/src/index.js b/src/index.js index 8da182b..038c826 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,6 @@ 'use strict'; + import React, { PropTypes } from 'react'; import tweenState from 'react-tween-state'; @@ -7,7 +8,8 @@ import { StyleSheet, TouchableHighlight, View, - Text + Text, + Platform } from 'react-native'; var Accordion = React.createClass({ @@ -112,7 +114,7 @@ var Accordion = React.createClass({ }} > - {this.props.content} + {(Platform.OS === 'ios' || this.state.is_visible) ? this.props.content : null}