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..f565799 100644 --- a/examples/AccordionExample/.flowconfig +++ b/examples/AccordionExample/.flowconfig @@ -1,65 +1,58 @@ [ignore] # We fork some components by platform. -.*/*.web.js -.*/*.android.js +.*/*[.]android.js -# Some modules have their own node_modules with overlap -.*/node_modules/node-haste/.* +# Ignore templates with `@flow` in header +.*/local-cli/generator.* -# Ugh -.*/node_modules/babel.* -.*/node_modules/babylon.* -.*/node_modules/invariant.* +# Ignore malformed json +.*/node_modules/y18n/test/.*\.json -# 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 +# Ignore the website subdir +/website/.* -# Flow has a built-in definition for the 'react' module which we prefer to use -# over the currently-untyped source -.*/node_modules/react/react.js -.*/node_modules/react/lib/React.js -.*/node_modules/react/lib/ReactDOM.js +# Ignore BUCK generated dirs +/\.buckd/ -# Ignore commoner tests -.*/node_modules/commoner/test/.* +# Ignore unexpected extra @providesModule +.*/node_modules/commoner/test/source/widget/share.js -# See https://github.com/facebook/flow/issues/442 -.*/react-tools/node_modules/commoner/lib/reader.js - -# Ignore jest -.*/node_modules/jest-cli/.* - -# Ignore Website -.*/website/.* +# Ignore duplicate module providers +# For RN Apps installed via npm, "Libraries" folder is inside node_modules/react-native but in the source repo it is in the root +.*/Libraries/react-native/React.js +.*/Libraries/react-native/ReactNative.js +.*/node_modules/jest-runtime/build/__tests__/.* [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\\.\\(3[0-2]\\|[1-2][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) +suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(3[0-2]\\|1[0-9]\\|[1-2][0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy +unsafe.enable_getters_and_setters=true + [version] -0.20.1 +^0.32.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/android/app/BUCK b/examples/AccordionExample/android/app/BUCK new file mode 100644 index 0000000..319fcda --- /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/src/main/java/com/accordionexample/MainActivity.java b/examples/AccordionExample/android/app/src/main/java/com/accordionexample/MainActivity.java index 2656a7e..4ae6da6 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 @@ -1,11 +1,6 @@ package com.accordionexample; import com.facebook.react.ReactActivity; -import com.facebook.react.ReactPackage; -import com.facebook.react.shell.MainReactPackage; - -import java.util.Arrays; -import java.util.List; public class MainActivity extends ReactActivity { @@ -17,23 +12,4 @@ public class MainActivity extends ReactActivity { protected String getMainComponentName() { return "AccordionExample"; } - - /** - * Returns whether dev mode should be enabled. - * This enables e.g. the dev menu. - */ - @Override - 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. - */ - @Override - protected List getPackages() { - return Arrays.asList( - new MainReactPackage()); - } } diff --git a/examples/AccordionExample/android/app/src/main/java/com/accordionexample/MainApplication.java b/examples/AccordionExample/android/app/src/main/java/com/accordionexample/MainApplication.java new file mode 100644 index 0000000..95d0b02 --- /dev/null +++ b/examples/AccordionExample/android/app/src/main/java/com/accordionexample/MainApplication.java @@ -0,0 +1,35 @@ +package com.accordionexample; + +import android.app.Application; +import android.util.Log; + +import com.facebook.react.ReactApplication; +import com.facebook.react.ReactInstanceManager; +import com.facebook.react.ReactNativeHost; +import com.facebook.react.ReactPackage; +import com.facebook.react.shell.MainReactPackage; + +import java.util.Arrays; +import java.util.List; + +public class MainApplication extends Application implements ReactApplication { + + private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { + @Override + protected boolean getUseDeveloperSupport() { + return BuildConfig.DEBUG; + } + + @Override + protected List getPackages() { + return Arrays.asList( + new MainReactPackage() + ); + } + }; + + @Override + public ReactNativeHost getReactNativeHost() { + return mReactNativeHost; + } +} 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.ios.js b/examples/AccordionExample/index.ios.js index 0a7d93e..78ccc4e 100644 --- a/examples/AccordionExample/index.ios.js +++ b/examples/AccordionExample/index.ios.js @@ -9,16 +9,13 @@ import { StyleSheet, Text, TouchableHighlight, - View + View, + Easing } from 'react-native'; import Accordion from 'react-native-accordion'; import { range } from 'lodash'; class AccordionExample extends Component { - componentDidMount() { - StatusBarIOS.setStyle("light-content"); - } - render() { return ( ); } diff --git a/examples/AccordionExample/ios/AccordionExample.xcodeproj/project.pbxproj b/examples/AccordionExample/ios/AccordionExample.xcodeproj/project.pbxproj index 3101e3c..df58a22 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,16 +577,12 @@ isa = XCBuildConfiguration; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - ); GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", ); INFOPLIST_FILE = AccordionExampleTests/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.2; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AccordionExample.app/AccordionExample"; @@ -596,12 +594,8 @@ 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; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AccordionExample.app/AccordionExample"; @@ -612,6 +606,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CURRENT_PROJECT_VERSION = 1; DEAD_CODE_STRIPPING = NO; HEADER_SEARCH_PATHS = ( "$(inherited)", @@ -620,8 +615,13 @@ ); INFOPLIST_FILE = "AccordionExample/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - OTHER_LDFLAGS = "-ObjC"; + OTHER_LDFLAGS = ( + "$(inherited)", + "-ObjC", + "-lc++", + ); PRODUCT_NAME = AccordionExample; + VERSIONING_SYSTEM = "apple-generic"; }; name = Debug; }; @@ -629,6 +629,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CURRENT_PROJECT_VERSION = 1; HEADER_SEARCH_PATHS = ( "$(inherited)", /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, @@ -636,8 +637,13 @@ ); INFOPLIST_FILE = "AccordionExample/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - OTHER_LDFLAGS = "-ObjC"; + OTHER_LDFLAGS = ( + "$(inherited)", + "-ObjC", + "-lc++", + ); PRODUCT_NAME = AccordionExample; + VERSIONING_SYSTEM = "apple-generic"; }; name = Release; }; @@ -680,7 +686,7 @@ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, "$(SRCROOT)/../node_modules/react-native/React/**", ); - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -720,7 +726,7 @@ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, "$(SRCROOT)/../node_modules/react-native/React/**", ); - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; diff --git a/examples/AccordionExample/ios/AccordionExample/AppDelegate.m b/examples/AccordionExample/ios/AccordionExample/AppDelegate.m index 96eb605..a6f9ed0 100644 --- a/examples/AccordionExample/ios/AccordionExample/AppDelegate.m +++ b/examples/AccordionExample/ios/AccordionExample/AppDelegate.m @@ -9,6 +9,7 @@ #import "AppDelegate.h" +#import "RCTBundleURLProvider.h" #import "RCTRootView.h" @implementation AppDelegate @@ -17,34 +18,13 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( { NSURL *jsCodeLocation; - /** - * Loading JavaScript code - uncomment the one you want. - * - * OPTION 1 - * Load from development server. Start the server from the repository root: - * - * $ npm start - * - * To run on device, change `localhost` to the IP address of your computer - * (you can get this by typing `ifconfig` into the terminal and selecting the - * `inet` value under `en0:`) and make sure your computer and iOS device are - * on the same Wi-Fi network. - */ - - jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"]; - - /** - * OPTION 2 - * Load from pre-bundled file on disk. The static bundle is automatically - * generated by "Bundle React Native code and images" build step. - */ - -// jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; + jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil]; RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation 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/examples/AccordionExample/package.json b/examples/AccordionExample/package.json index 05d75cd..a5aa397 100644 --- a/examples/AccordionExample/package.json +++ b/examples/AccordionExample/package.json @@ -7,8 +7,8 @@ }, "dependencies": { "lodash": "3.10.1", - "react": "15.1.0", - "react-native": "0.28.0", + "react": "15.3.2", + "react-native": "^0.35.0", "react-native-accordion": "../.." } } diff --git a/package.json b/package.json index 9e625de..ffc0ce2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-accordion", - "version": "1.0.1", + "version": "2.0.0", "description": "An Accordion Component for React Native", "main": "index.js", "scripts": { @@ -25,6 +25,7 @@ }, "homepage": "https://github.com/naoufal/react-native-accordion", "dependencies": { - "react-tween-state": "0.0.5" + "create-react-class": "15.6.0", + "prop-types": "^15.5.10" } } diff --git a/src/index.js b/src/index.js index 8da182b..d57f6a6 100644 --- a/src/index.js +++ b/src/index.js @@ -1,35 +1,34 @@ 'use strict'; -import React, { PropTypes } from 'react'; -import tweenState from 'react-tween-state'; - +import React from 'react'; import { - StyleSheet, TouchableHighlight, View, - Text + Animated, + Easing } from 'react-native'; -var Accordion = React.createClass({ - mixins: [tweenState.Mixin], +const createReactClass = require('create-react-class'); +const PropTypes = require('prop-types'); +const Accordion = createReactClass({ propTypes: { - activeOpacity: React.PropTypes.number, - animationDuration: React.PropTypes.number, - content: React.PropTypes.element.isRequired, - easing: React.PropTypes.string, - expanded: React.PropTypes.bool, - header: React.PropTypes.element.isRequired, - onPress: React.PropTypes.func, - underlayColor: React.PropTypes.string, - style: React.PropTypes.object + activeOpacity: PropTypes.number, + animationDuration: PropTypes.number, + content: PropTypes.element.isRequired, + easing: PropTypes.func, + expanded: PropTypes.bool, + header: PropTypes.element.isRequired, + onPress: PropTypes.func, + underlayColor: PropTypes.string, + style: PropTypes.object }, getDefaultProps() { return { activeOpacity: 1, animationDuration: 300, - easing: 'linear', + easing: Easing.linear, expanded: false, underlayColor: '#000', style: {} @@ -38,8 +37,8 @@ var Accordion = React.createClass({ getInitialState() { return { - is_visible: false, - height: 0, + is_visible: this.props.expanded, + height: null, content_height: 0 }; }, @@ -54,12 +53,14 @@ var Accordion = React.createClass({ toggle() { this.state.is_visible = !this.state.is_visible; - - this.tweenState('height', { - easing: tweenState.easingTypes[this.props.easing], - duration: this.props.animationDuration, - endValue: this.state.height === 0 ? this.state.content_height : 0 - }); + Animated.timing( + this.state.height, + { + toValue: this.state.is_visible ? this.state.content_height : 0, + duration: this.props.animationDuration, + easing: this.props.easing + } + ).start(); }, _onPress() { @@ -70,25 +71,17 @@ var Accordion = React.createClass({ } }, - _getContentHeight() { - if (this.refs.AccordionContent) { - this.refs.AccordionContent.measure((ox, oy, width, height, px, py) => { - // Sets content height in state - this.setState({ - height: this.props.expanded ? height : 0, - content_height: height - }); + _getContentHeight(event) { + const height = event.nativeEvent.layout.height; + if (this.state.content_height === 0) { + this.setState({ + content_height: height }); + this.state.height = new Animated.Value(0); + this.state.height.setValue(this.props.expanded ? height : 0); } }, - componentDidMount() { - // Gets content height when component mounts - // without setTimeout, measure returns 0 for every value. - // See https://github.com/facebook/react-native/issues/953 - setTimeout(this._getContentHeight); - }, - render() { return ( /*jshint ignore:start */ @@ -105,16 +98,17 @@ var Accordion = React.createClass({ > {this.props.header} - this._getContentHeight(event)} style={{ - height: this.getTweeningValue('height') + height: this.state.height }} > {this.props.content} - + /*jshint ignore:end */ );