Skip to content

width height animation example #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .migration_backup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"tar.gz": "^1.0.7",
"tns-platform-declarations": "6.0.1",
"tslint": "5.11.0",
"typescript": "3.4.1"
"typescript": "3.4.5"
},
"scripts": {
"lint": "eslint \"app/**/*.js\"",
Expand Down
33 changes: 33 additions & 0 deletions app/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var application = require("tns-core-modules/application");
var platformModule = require("tns-core-modules/platform");
var applicationSettingsModule = require("tns-core-modules/application-settings");
var deepLinkDataModule = require("./shared/deep-link-data");
if (platformModule.isIOS) {
var mydelegate = require("./delegate/my-delegate");
application.ios.delegate = mydelegate.MyDelegate;
}
function launchExample() {
var rootView = application.getRootView();
if (applicationSettingsModule.hasKey("gotoexample")) {
var value = applicationSettingsModule.getString("gotoexample");
if (value !== "") {
applicationSettingsModule.remove("gotoexample");
rootView.navigate({
moduleName: value,
clearHistory: true
});
}
}
}
application.on(application.resumeEvent, function (args) {
if (args.android) {
var dld = new deepLinkDataModule.DeepLinkData("", args.android);
launchExample();
}
else if (args.ios) {
launchExample();
}
});
application.run({ moduleName: "app-root" });
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ NativeScript lets you animate the following properties:
`translateX` and `translateY`
`scaleX` and `scaleY`
`rotate`
`width` and `height`

In every animation, you can control the following properties:

Expand Down
6 changes: 4 additions & 2 deletions app/ns-ui-widgets-category/animations/animations-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ const navigationLinks = [
new link("Animated Properties", "ns-ui-widgets-category/animations/animating-properties/animating-properties-page"),
new link("Chained Animations", "ns-ui-widgets-category/animations/chaining-animations/chaining-animations-page"),
new link("Animating Multiple Views", "ns-ui-widgets-category/animations/multiple-views-animation/multiple-views-page"),
new link("Properties originX and originY", "ns-ui-widgets-category/animations/origin-properties/property-origin-page")
new link("Properties originX and originY", "ns-ui-widgets-category/animations/origin-properties/property-origin-page"),
new link("Properties width and height", "ns-ui-widgets-category/animations/width-height-properties/width-height-properties-page")
];

const navigationLinksTsc = [
new link("Animated Properties", "ns-ui-widgets-category/animations/animating-properties/animating-properties-ts-page"),
new link("Chained Animations", "ns-ui-widgets-category/animations/chaining-animations/chaining-animations-ts-page"),
new link("Animating Multiple Views", "ns-ui-widgets-category/animations/multiple-views-animation/multiple-views-ts-page"),
new link("Properties originX and originY", "ns-ui-widgets-category/animations/origin-properties/property-origin-ts-page")
new link("Properties originX and originY", "ns-ui-widgets-category/animations/origin-properties/property-origin-ts-page"),
new link("Properties width and height", "ns-ui-widgets-category/animations/width-height-properties/width-height-properties-ts-page")
];

// >> animations-imports
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Since {N} 6.0, we can animate the `width` and `height` properties of views. On the snippets below are demonstrated, how to configure those animations:

<snippet id='animation-properties-width-height'/>
<snippet id='animation-properties-width-height-ts'/>
<snippet id='animation-properties-width-height-xml'/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Label {
color: white;
background-color:blue;
border-radius: 20;
margin: 16;
padding: 8;
horizontal-align: center;
vertical-align: top;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// >> animation-properties-width-height
const AnimationCurve = require("tns-core-modules/ui/enums").AnimationCurve;

function animateWidth(args) {
const button = args.object;
const page = button.page;
const myView = page.getViewById("lbl");

myView.animate({
width:320,
duration: 1000,
curve: AnimationCurve.easeIn
});
}
exports.animateWidth = animateWidth;

function animateHeight(args) {
const button = args.object;
const page = button.page;
const myView = page.getViewById("lbl");

myView.animate({
height:400,
duration: 1000,
curve: AnimationCurve.easeIn
});
}
exports.animateHeight = animateHeight;
// << animation-properties-width-height
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Page xmlns="http://www.nativescript.org/tns.xsd">
<Page.actionBar>
<ActionBar title="Animating Width & Height Properties" />
</Page.actionBar>
<!-- >> animation-properties-width-height-xml -->
<GridLayout rows="auto, auto, *">
<Button row="0" text="Animate height" tap="animateHeight" class="btn btn-primary btn-active" width="80%"/>
<Button row="1" text="Animate width" tap="animateWidth" class="btn btn-primary btn-active" width="80%"/>
<Label row="2" id="lbl" text="NativeScript" textWrap="true" marginTop="50"/>
</GridLayout>
<!-- << animation-properties-width-height-xml -->
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Label {
color: white;
background-color:blue;
border-radius: 20;
margin: 16;
padding: 8;
horizontal-align: center;
vertical-align: top;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// >> animation-properties-width-height-ts
import { AnimationCurve } from "tns-core-modules/ui/enums";
import { View } from "tns-core-modules/ui/core/view";

export function animateWidth(args) {
let button = args.object;
let page = button.page;
let view = <View>page.getViewById("lbl");

view.animate({
width: 320,
duration: 1000,
curve: AnimationCurve.easeIn
});
}

export function animateHeight(args) {
let button = args.object;
let page = button.page;
let view = <View>page.getViewById("lbl");

view.animate({
height: 400,
duration: 1000,
curve: AnimationCurve.easeIn
});
}
// << animation-properties-width-height-ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Page xmlns="http://www.nativescript.org/tns.xsd">
<Page.actionBar>
<ActionBar title="Animating Width & Height Properties" />
</Page.actionBar>
<GridLayout rows="auto, auto, *">
<Button row="0" text="Animate height" tap="animateHeight" class="btn btn-primary btn-active" width="80%"/>
<Button row="1" text="Animate width" tap="animateWidth" class="btn btn-primary btn-active" width="80%"/>
<Label row="2" id="lbl" text="NativeScript" textWrap="true" marginTop="50"/>
</GridLayout>
</Page>
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"version": "6.0.0"
},
"tns-ios": {
"version": "6.0.0"
"version": "6.0.1"
}
},
"dependencies": {
Expand All @@ -36,7 +36,7 @@
"eslint": "~5.9.0",
"fs-extra": "^0.30.0",
"markdown-snippet-injector": "^0.2.4",
"nativescript-dev-webpack": "1.0.0",
"nativescript-dev-webpack": "1.0.1",
"tar.gz": "^1.0.7",
"tns-platform-declarations": "6.0.1",
"tslint": "5.11.0",
Expand Down
2 changes: 0 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,6 @@ module.exports = env => {
new CleanWebpackPlugin(itemsToClean, { verbose: !!verbose }),
// Copy assets to out dir. Add your own globs as needed.
new CopyWebpackPlugin([
{ from: { glob: "ns-ui-widgets-category/web-view/source-load/*.html" } },
{ from: { glob: "ns-ui-widgets-category/placeholder/platform-files/*.ts" } },
{ from: { glob: "fonts/**" } },
{ from: { glob: "**/*.jpg" } },
{ from: { glob: "**/*.png" } },
Expand Down