From a7d3b292fda11408a3d41fb76c6bde24af32a12b Mon Sep 17 00:00:00 2001 From: Brad Martin Date: Sun, 1 Oct 2017 22:29:09 -0500 Subject: [PATCH] plugin updates --- .gitignore | 28 ++++++++++- .travis.yml | 70 ++++++++++++++++++++++++++++ LICENSE.md | 21 +++++++++ demo/app/app.ts | 2 + demo/app/main-page.ts | 49 +++++++++++++++++++ demo/app/multifab.css | 45 +++++++++--------- demo/app/multifab.ts | 32 +++++++++++++ demo/app/vendor-platform.android.ts | 9 ++++ demo/app/vendor-platform.ios.ts | 0 demo/app/vendor.ts | 3 ++ demo/karma.conf.js | 62 ++++++++++++++++++++++++ demo/package.json | 54 +++++++++++++++++---- demo/references.d.ts | 2 + demo/tsconfig.json | 27 +++++++++++ src/fab-common.ts | 45 ++++++------------ src/fab.android.ts | 20 ++------ src/fab.ios.ts | 1 - src/index.d.ts | 2 +- src/package.json | 12 +++-- src/platforms/android/include.gradle | 20 ++++---- 20 files changed, 414 insertions(+), 90 deletions(-) create mode 100644 .travis.yml create mode 100644 LICENSE.md create mode 100644 demo/app/app.ts create mode 100644 demo/app/main-page.ts create mode 100644 demo/app/multifab.ts create mode 100644 demo/app/vendor-platform.android.ts create mode 100644 demo/app/vendor-platform.ios.ts create mode 100644 demo/app/vendor.ts create mode 100644 demo/karma.conf.js create mode 100644 demo/references.d.ts create mode 100644 demo/tsconfig.json diff --git a/.gitignore b/.gitignore index 270cb45..439a610 100644 --- a/.gitignore +++ b/.gitignore @@ -212,5 +212,31 @@ demo/lib/* src/*.js /*.js +demo/app/*.js demo/node_modules/ -node_modules/ \ No newline at end of file +node_modules/ + +.vscode +.idea +.DS_Store +*.js +*.js.map +*.log +src/*.d.ts +!src/index.d.ts +!src/references.d.ts +!src/scripts/*.js +!seed-tests/*.js +seed-tests/seed-copy/**/*.* +seed-tests/seed-copy-new-git-repo/**/*.* +!demo/karma.conf.js +!demo/app/tests/*.js +demo/*.d.ts +!demo/references.d.ts +demo/lib +demo/platforms +node_modules +publish/src +publish/package +demo/report/report.html +demo/report/stats.json \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..ef88e01 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,70 @@ +branches: + only: + - master +matrix: + include: + - stage: "Lint" + language: node_js + os: linux + node_js: "6" + script: cd src && npm run ci.tslint && cd ../demo && npm run ci.tslint + - stage: "Build and Test" + env: + - BuildAndroid="25" + language: android + os: linux + jdk: oraclejdk8 + before_install: nvm install stable + script: + - cd src && npm i && npm run tsc && cd ../demo + - travis_wait travis_retry tns build android + - os: osx + env: + - BuildiOS="10.3" + - Xcode="8.3" + osx_image: xcode8.3 + language: node_js + node_js: "6" + jdk: oraclejdk8 + script: + - cd src && npm i && npm run tsc && cd ../demo + - travis_wait travis_retry tns build ios + - os: linux + language: android + env: + - TestVersion="latest" + jdk: oraclejdk8 + before_install: + - nvm install stable + before_script: + - cd seed-tests && npm i + - echo no | android create avd --force -n test -t android-21 -b armeabi-v7a + - emulator -avd test -no-audio -no-window & + - android-wait-for-emulator + script: travis_wait travis_retry npm run test.android + dist: precise + - os: osx + env: + - TestVersion="latest" + language: node_js + node_js: "6" + jdk: oraclejdk8 + osx_image: xcode8.3 + before_script: + - cd seed-tests && npm i + script: travis_wait travis_retry npm run test.ios + +android: + components: + - tools + - platform-tools + - build-tools-25.0.2 + - android-25 + - extra-android-m2repository + - sys-img-armeabi-v7a-android-21 + +install: + - npm install -g nativescript + - tns usage-reporting disable + - tns error-reporting disable + \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..8b998fb --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) - do whatever you want with this - just don't be a bitch about it. + +nativescript-floatingactionbutton +Copyright (c) 2017, Brad Martin + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/demo/app/app.ts b/demo/app/app.ts new file mode 100644 index 0000000..0a218d3 --- /dev/null +++ b/demo/app/app.ts @@ -0,0 +1,2 @@ +import * as app from "tns-core-modules/application"; +app.start({ moduleName: "main-page" }); diff --git a/demo/app/main-page.ts b/demo/app/main-page.ts new file mode 100644 index 0000000..30e5bf6 --- /dev/null +++ b/demo/app/main-page.ts @@ -0,0 +1,49 @@ +import * as app from "tns-core-modules/application"; +import * as observable from "tns-core-modules/data/observable"; +import * as observableArrayModule from "tns-core-modules/data/observable-array"; +import * as platformModule from "tns-core-modules/platform"; +import * as frameModule from "tns-core-modules/ui/frame"; +import * as color from "tns-core-modules/color"; + +const users = [ + { name: "Billy Bob" }, + { name: "Tweeder" }, + { name: "Mox" }, + { name: "Coach" }, + { name: "Lance" }, + { name: "Johnson" }, + { name: "William" }, + { name: "Franklin" }, + { name: "Billy Bob" }, + { name: "Tweeder" }, + { name: "Mox" }, + { name: "Coach" }, + { name: "Lance" }, + { name: "Johnson" }, + { name: "William" }, + { name: "Franklin" } +]; +var viewModel = observable.fromObject({ + users: new observableArrayModule.ObservableArray(users) +}); + +export function pageLoaded(args) { + const page = args.object; + if (platformModule.isAndroid) { + // Change statusbar color on Lollipop + if (platformModule.device.sdkVersion >= "21") { + const window = app.android.startActivity.getWindow(); + window.setStatusBarColor(new color.Color("#303F9F").android); + } + } + page.bindingContext = viewModel; +} +// exports.pageLoaded = pageLoaded; + +export function fabTap(args) { + (viewModel as any).users.unshift({ name: "Gary" }); +} + +export function goMultiFab(args) { + frameModule.topmost().navigate("multifab"); +} diff --git a/demo/app/multifab.css b/demo/app/multifab.css index 4ae0043..9ff77c1 100644 --- a/demo/app/multifab.css +++ b/demo/app/multifab.css @@ -1,32 +1,35 @@ .fab-button { - height: 50; - width: 50; - margin: 15; - color: #FFF; - background-color: #ff4081; + height: 50; + width: 50; + margin: 15; + color: #fff; + background-color: #ff4081; } -.top-left{ - horizontal-align: left; - vertical-align: top; +.top-left { + background-color: red; + horizontal-align: left; + vertical-align: top; } -.top-right{ - horizontal-align: right; - vertical-align: top; +.top-right { + background-color: #336699; + horizontal-align: right; + vertical-align: top; } -.bottom-left{ - horizontal-align: left; - vertical-align: bottom; +.bottom-left { + background-color: #fff000; + horizontal-align: left; + vertical-align: bottom; } -.bottom-right{ - horizontal-align: right; - vertical-align: bottom; +.bottom-right { + horizontal-align: right; + vertical-align: bottom; } -.center{ - horizontal-align: center; - vertical-align: center; -} \ No newline at end of file +.center { + horizontal-align: center; + vertical-align: center; +} diff --git a/demo/app/multifab.ts b/demo/app/multifab.ts new file mode 100644 index 0000000..25f36ad --- /dev/null +++ b/demo/app/multifab.ts @@ -0,0 +1,32 @@ +import * as app from "tns-core-modules/application"; +import * as observable from "tns-core-modules/data/observable"; +import * as observableArrayModule from "tns-core-modules/data/observable-array"; +import * as platformModule from "tns-core-modules/platform"; +import * as color from "tns-core-modules/color"; +import * as frame from "tns-core-modules/ui/frame"; + +export function pageLoaded(args) { + const page = args.object; + if (platformModule.isAndroid) { + // Change statusbar color on Lollipop + if (platformModule.device.sdkVersion >= "21") { + const window = app.android.startActivity.getWindow(); + window.setStatusBarColor(new color.Color("#303F9F").android); + } + } +} +// exports.pageLoaded = pageLoaded; + +export function fabTap(args) { + alert("tap"); + frame.topmost().goBack(); +} + +export function animate(args) { + args.object.animate({ + duration: 500, + target: args.object, + opacity: 0, + translate: { x: 100, y: 200 } + }); +} diff --git a/demo/app/vendor-platform.android.ts b/demo/app/vendor-platform.android.ts new file mode 100644 index 0000000..ff64887 --- /dev/null +++ b/demo/app/vendor-platform.android.ts @@ -0,0 +1,9 @@ +require("application"); +if (!global["__snapshot"]) { + /* + In case snapshot generation is enabled these modules will get into the bundle but will not be required/evaluated. + The snapshot webpack plugin will add them to the tns-java-classes.js bundle file. This way, they will be evaluated on app start as early as possible. + */ + require("ui/frame"); + require("ui/frame/activity"); +} diff --git a/demo/app/vendor-platform.ios.ts b/demo/app/vendor-platform.ios.ts new file mode 100644 index 0000000..e69de29 diff --git a/demo/app/vendor.ts b/demo/app/vendor.ts new file mode 100644 index 0000000..5c562b3 --- /dev/null +++ b/demo/app/vendor.ts @@ -0,0 +1,3 @@ +require("./vendor-platform"); + +require("bundle-entry-points"); diff --git a/demo/karma.conf.js b/demo/karma.conf.js new file mode 100644 index 0000000..b3b2297 --- /dev/null +++ b/demo/karma.conf.js @@ -0,0 +1,62 @@ +module.exports = function(config) { + config.set({ + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: "", + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ["jasmine"], + + // list of files / patterns to load in the browser + files: ["app/**/*.js"], + + // list of files to exclude + exclude: [], + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: {}, + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ["progress"], + + // web server port + port: 9876, + + // enable / disable colors in the output (reporters and logs) + colors: true, + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: [], + + customLaunchers: { + android: { + base: "NS", + platform: "android" + }, + ios: { + base: "NS", + platform: "ios" + }, + ios_simulator: { + base: "NS", + platform: "ios", + arguments: ["--emulator"] + } + }, + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: true + }); +}; diff --git a/demo/package.json b/demo/package.json index 3879359..2fd49b9 100644 --- a/demo/package.json +++ b/demo/package.json @@ -1,21 +1,59 @@ { "nativescript": { "id": "org.nativescript.floatingactionbutton", - "tns-android": { - "version": "3.1.0" - }, "tns-ios": { "version": "3.2.0" + }, + "tns-android": { + "version": "3.2.0" } }, "dependencies": { "nativescript-floatingactionbutton": "../src", - "tns-core-modules": "3.1.0" + "nativescript-unit-test-runner": "^0.3.4", + "tns-core-modules": "^3.1.1" }, "devDependencies": { - "babel-traverse": "6.24.1", - "babel-types": "6.24.1", - "babylon": "6.17.0", - "lazy": "1.0.11" + "awesome-typescript-loader": "~3.1.3", + "babel-traverse": "6.12.0", + "babel-types": "6.11.1", + "babylon": "6.8.4", + "copy-webpack-plugin": "~4.0.1", + "extract-text-webpack-plugin": "~3.0.0", + "filewalker": "0.1.2", + "jasmine-core": "^2.5.2", + "karma": "^1.3.0", + "karma-jasmine": "^1.0.2", + "karma-nativescript-launcher": "^0.4.0", + "lazy": "1.0.11", + "nativescript-css-loader": "~0.26.0", + "nativescript-dev-typescript": "libs", + "nativescript-dev-webpack": "^0.7.3", + "raw-loader": "~0.5.1", + "resolve-url-loader": "~2.1.0", + "tns-platform-declarations": "^3.1.0", + "tslint": "~5.4.3", + "typescript": "~2.3.0", + "webpack": "~3.2.0", + "webpack-bundle-analyzer": "^2.8.2", + "webpack-sources": "~1.0.1" + }, + "build.plugin": "cd ../src && npm run build", + "ci.tslint": "npm i && tslint --config '../tslint.json' 'app/**/*.ts' --exclude '**/node_modules/**'", + "ns-bundle": "ns-bundle", + "publish-ios-bundle": "npm run ns-bundle --ios --publish-app", + "generate-android-snapshot": "generate-android-snapshot --targetArchs arm,arm64,ia32 --install", + "start-android-bundle": "npm run ns-bundle --android --run-app --uglify --snapshot", + "start-ios-bundle": "npm run ns-bundle --ios --run-app --uglify", + "build-android-bundle": "npm run ns-bundle --android --build-app --uglify --snapshot", + "build-ios-bundle": "npm run ns-bundle --ios --build-app --uglify", + "scripts": { + "ns-bundle": "ns-bundle", + "publish-ios-bundle": "npm run ns-bundle --ios --publish-app", + "generate-android-snapshot": "generate-android-snapshot --targetArchs arm,arm64,ia32 --install", + "start-android-bundle": "npm run ns-bundle --android --run-app", + "start-ios-bundle": "npm run ns-bundle --ios --run-app", + "build-android-bundle": "npm run ns-bundle --android --build-app", + "build-ios-bundle": "npm run ns-bundle --ios --build-app" } } diff --git a/demo/references.d.ts b/demo/references.d.ts new file mode 100644 index 0000000..992a504 --- /dev/null +++ b/demo/references.d.ts @@ -0,0 +1,2 @@ +/// +/// \ No newline at end of file diff --git a/demo/tsconfig.json b/demo/tsconfig.json new file mode 100644 index 0000000..dfdaf6c --- /dev/null +++ b/demo/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + "target": "es5", + "module": "commonjs", + "declaration": false, + "removeComments": true, + "noLib": false, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "lib": ["es6", "dom"], + "pretty": true, + "allowUnreachableCode": false, + "allowUnusedLabels": false, + "noEmitHelpers": true, + "noEmitOnError": false, + "noImplicitAny": false, + "noImplicitReturns": true, + "noImplicitUseStrict": false, + "noFallthroughCasesInSwitch": true, + "baseUrl": ".", + "paths": { + "*": ["./node_modules/*"] + } + }, + "exclude": ["node_modules", "platforms"], + "compileOnSave": false +} diff --git a/src/fab-common.ts b/src/fab-common.ts index 1c7150b..86ff53f 100644 --- a/src/fab-common.ts +++ b/src/fab-common.ts @@ -25,23 +25,14 @@ export class FloatingActionButtonBase extends View implements definitions.Fab { public hideAnimationDuration: number; public rippleColor: Color; public icon: string; - public backColor: Color; - - constructor() { - super(); - console.log("constructor super"); - } + onLa; onLoaded() { super.onLoaded(); if (this.swipeEventAttached === false) { const fab = this; - // maybe try to get the fab view a different way - const xFab = topmost().getViewById(fab.id); if (this.hideOnSwipeOfView) { - const swipeItem = topmost().getViewById( - this.hideOnSwipeOfView - ); + const swipeItem = topmost().getViewById(this.hideOnSwipeOfView); const animationType = this.swipeAnimation ? this.swipeAnimation : "slideDown"; @@ -56,15 +47,19 @@ export class FloatingActionButtonBase extends View implements definitions.Fab { if (args.deltaY < -10) { switch (animationType) { case "slideUp": - fab.animate({ - target: fab, - translate: { - x: 0, - y: -200 - }, - opacity: 0, - duration: 400 - }); + try { + fab.animate({ + target: fab, + translate: { + x: 0, + y: -200 + }, + opacity: 0, + duration: 400 + }); + } catch (error) { + console.log(error); + } break; case "slideDown": fab.animate({ @@ -187,16 +182,6 @@ export class FloatingActionButtonBase extends View implements definitions.Fab { } } -export const backColorProperty = new Property({ - name: "backColor", - equalityComparer: Color.equals, - valueConverter: v => new Color(v), - valueChanged: (fab, oldValue, newValue) => { - fab.style.backgroundColor = newValue; - } -}); -backColorProperty.register(FloatingActionButtonBase); - export const iconProperty = new Property({ name: "icon", affectsLayout: true diff --git a/src/fab.android.ts b/src/fab.android.ts index 68d9b61..37ab071 100644 --- a/src/fab.android.ts +++ b/src/fab.android.ts @@ -1,6 +1,5 @@ import { FloatingActionButtonBase, - backColorProperty, rippleColorProperty, iconProperty } from "./fab-common"; @@ -52,19 +51,6 @@ export class Fab extends FloatingActionButtonBase { this.nativeView.setId(this._androidViewId); } - [backColorProperty.setNative](value: Color) { - if (value) { - try { - this.nativeView.setBackgroundTintList( - android.content.res.ColorStateList.valueOf(value.android) - ); - } catch (error) { - // do nothing, catch bad color value - console.log("bad background-color value: ", error); - } - } - } - [backgroundColorProperty.getDefault](): android.content.res.ColorStateList { return this.nativeView.getBackgroundTintList(); } @@ -79,7 +65,11 @@ export class Fab extends FloatingActionButtonBase { // Resetting with the default value; newValue = value; } - this.nativeView.setBackgroundTintList(newValue); + try { + this.nativeView.setBackgroundTintList(newValue); + } catch (err) { + console.log(`err: `, err); + } } [backgroundInternalProperty.setNative](value: any) { diff --git a/src/fab.ios.ts b/src/fab.ios.ts index ea67733..508ae05 100644 --- a/src/fab.ios.ts +++ b/src/fab.ios.ts @@ -1,6 +1,5 @@ import { FloatingActionButtonBase, - backColorProperty, rippleColorProperty, iconProperty } from "./fab-common"; diff --git a/src/index.d.ts b/src/index.d.ts index b994971..ae6dbe1 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -12,5 +12,5 @@ export declare class Fab extends View { public hideAnimationDuration: number; public rippleColor: Color; public icon: string; - public backColor: Color; + // public backColor: Color; } diff --git a/src/package.json b/src/package.json index e425fe9..2d6c948 100644 --- a/src/package.json +++ b/src/package.json @@ -15,12 +15,18 @@ "url": "https://github.com/bradmartin/nativescript-floatingactionbutton" }, "scripts": { + "tsc": "tsc -skipLibCheck", + "build": "npm i && tsc", + "postclone": "npm i && node scripts/postclone.js && cd ../demo && npm i && cd ../src && npm run plugin.link", + "test.android": "npm i && npm run tsc && npm run tslint && cd ../demo && tns build android && tns test android --justlaunch", + "test.ios": "npm i && npm run tsc && npm run tslint && cd ../demo && tns build ios && tns test ios --justlaunch", + "tslint": "cd .. && tslint \"**/*.ts\" --config tslint.json --exclude \"**/node_modules/**\"", "plugin.link": "npm link && cd ../demo && npm link nativescript-floatingactionbutton && cd ../src", - "plugin.tscwatch": "npm run tsc -w", + "plugin.tscwatch": "npm run tsc -- -w", "demo.ios": "npm i && npm run tsc && cd ../demo && tns run ios --syncAllFiles", "demo.android": "npm i && npm run tsc && cd ../demo && tns run android --syncAllFiles", "demo.reset": "cd ../demo && rimraf platforms", - "plugin.prepare": "npm run tsc && cd ../demo && tns plugin remove nativescript-floatingactionbuttion && tns plugin add ../src", + "plugin.prepare": "npm run tsc && cd ../demo && tns plugin remove nativescript-floatingactionbutton && tns plugin add ../src", "clean": "cd ../demo && rimraf hooks node_modules platforms && cd ../src && rimraf node_modules && npm run plugin.link", "ci.tslint": "npm i && tslint '**/*.ts' --config '../tslint.json' --exclude '**/node_modules/**'" }, @@ -73,7 +79,7 @@ "url": "https://github.com/sis0k0" } ], - "license": "Apache-2.0", + "license": "MIT", "bugs": "https://github.com/bradmartin/nativescript-floatingactionbutton/issues", "homepage": "https://github.com/bradmartin/nativescript-floatingactionbutton", "devDependencies": { diff --git a/src/platforms/android/include.gradle b/src/platforms/android/include.gradle index 3d3a943..7e13ccf 100644 --- a/src/platforms/android/include.gradle +++ b/src/platforms/android/include.gradle @@ -1,18 +1,18 @@ -//default elements -android { - productFlavors { - "nativescriptfloatingactionbutton" { - dimension "nativescriptfloatingactionbutton" - } - } +//default elements +android { + productFlavors { + "nativescriptfloatingactionbutton" { + dimension "nativescriptfloatingactionbutton" + } + } } dependencies { - def suppotVer = "22.2.0"; + def supportVer = "26.1.0"; if(project.hasProperty("supportVersion")) { - suppotVer = supportVersion + supportVer = supportVersion } - compile "com.android.support:design:$suppotVer" + compile "com.android.support:design:$supportVer" }