nativescript-parallax
Advanced tools
Comparing version 1.1.0 to 1.2.0
import { GridLayout } from 'ui/layouts/grid-layout'; | ||
import { View, AddChildFromBuilder } from 'ui/core/view'; | ||
import { StackLayout } from 'ui/layouts/stack-layout'; | ||
@@ -13,3 +12,7 @@ export declare class Header extends StackLayout { | ||
} | ||
export declare class ParallaxView extends GridLayout implements AddChildFromBuilder { | ||
export interface IMinimumHeights { | ||
portrait: number; | ||
landscape: number; | ||
} | ||
export declare class ParallaxView extends GridLayout { | ||
private _controlsToFade; | ||
@@ -27,11 +30,2 @@ private _childLayouts; | ||
constructor(); | ||
private setMinimumHeight(contentView, anchoredRow, minHeight); | ||
private getMinimumHeights(); | ||
private addDropShadow(marginTop, width); | ||
private shadowView(opacity, width); | ||
private fadeViews(topHeight, verticalOffset, viewsToFade); | ||
private getAnchoredTopHeight(topHeight, verticalOffset); | ||
private getTopViewHeight(topHeight, verticalOffset); | ||
displayDevWarning(message: string, ...viewsToCollapse: View[]): void; | ||
_addChildFromBuilder: (name: string, value: any) => void; | ||
} |
@@ -12,6 +12,4 @@ "use strict"; | ||
var absolute_layout_1 = require('ui/layouts/absolute-layout'); | ||
var view_1 = require('ui/core/view'); | ||
var label_1 = require('ui/label'); | ||
var stack_layout_1 = require('ui/layouts/stack-layout'); | ||
var color_1 = require('color'); | ||
var utilities_1 = require('./utilities'); | ||
var Header = (function (_super) { | ||
@@ -57,7 +55,2 @@ __extends(Header, _super); | ||
_super.call(this); | ||
this._addChildFromBuilder = function (name, value) { | ||
if (value instanceof view_1.View) { | ||
_this._childLayouts.push(value); | ||
} | ||
}; | ||
this._childLayouts = []; | ||
@@ -74,3 +67,3 @@ var headerView; | ||
var invalidSetup = false; | ||
this._minimumHeights = this.getMinimumHeights(); | ||
this._minimumHeights = utilities_1.ParallaxUtilities.getMinimumHeights(); | ||
if (this.bounce == null) { | ||
@@ -88,2 +81,3 @@ this.bounce = false; | ||
_this._loaded = true; | ||
_this._childLayouts = utilities_1.ParallaxUtilities.pluckViews(_this); | ||
_this.addRow(row); | ||
@@ -100,3 +94,3 @@ _this.addColumn(column); | ||
_this._childLayouts.forEach(function (element) { | ||
if (element instanceof Header) { | ||
if (element instanceof Header || (stack_layout_1.StackLayout && utilities_1.ParallaxUtilities.containsCssClass(element, 'header'))) { | ||
wrapperStackLayout_1.addChild(element); | ||
@@ -107,3 +101,3 @@ headerView = element; | ||
_this._childLayouts.forEach(function (element) { | ||
if (element instanceof Content) { | ||
if (element instanceof Content || (stack_layout_1.StackLayout && utilities_1.ParallaxUtilities.containsCssClass(element, 'content'))) { | ||
wrapperStackLayout_1.addChild(element); | ||
@@ -114,7 +108,7 @@ contentView = element; | ||
_this._childLayouts.forEach(function (element) { | ||
if (element instanceof Anchored) { | ||
if (element instanceof Anchored || (stack_layout_1.StackLayout && utilities_1.ParallaxUtilities.containsCssClass(element, 'anchor'))) { | ||
anchoredRow.addChild(element); | ||
if (element.dropShadow) { | ||
if (element.dropShadow || utilities_1.ParallaxUtilities.containsCssClass(element, 'dropShadow')) { | ||
anchoredRow.height = element.height; | ||
anchoredRow.addChild(_this.addDropShadow(element.height, element.width)); | ||
anchoredRow.addChild(utilities_1.ParallaxUtilities.addDropShadow(element.height, element.width)); | ||
} | ||
@@ -129,11 +123,11 @@ else { | ||
if (headerView == null || contentView == null) { | ||
_this.displayDevWarning('Parallax ScrollView Setup Invalid. You must have Header and Content tags', headerView, contentView, contentView); | ||
utilities_1.ParallaxUtilities.displayDevWarning(_this, 'Parallax ScrollView Setup Invalid. You must have Header and Content tags', headerView, contentView, contentView); | ||
return; | ||
} | ||
if (isNaN(headerView.height)) { | ||
_this.displayDevWarning('Header MUST have a height set.', headerView, anchoredRow, contentView); | ||
utilities_1.ParallaxUtilities.displayDevWarning(_this, 'Header MUST have a height set.', headerView, anchoredRow, contentView); | ||
return; | ||
} | ||
if (_this._includesAnchored && isNaN(anchoredRow.height)) { | ||
_this.displayDevWarning('Anchor MUST have a height set.', anchoredRow, headerView, contentView); | ||
utilities_1.ParallaxUtilities.displayDevWarning(_this, 'Anchor MUST have a height set.', anchoredRow, headerView, contentView); | ||
return; | ||
@@ -143,7 +137,7 @@ } | ||
if (_this._includesAnchored) { | ||
anchoredRow.marginTop = maxTopViewHeight; | ||
anchoredRow.translateY = maxTopViewHeight; | ||
if (app.android) { | ||
anchoredRow.marginTop = anchoredRow.marginTop - 5; | ||
anchoredRow.translateY = anchoredRow.translateY - 5; | ||
} | ||
contentView.marginTop = anchoredRow.height; | ||
contentView.translateY = anchoredRow.height; | ||
} | ||
@@ -172,12 +166,12 @@ if (_this.bounce === false) { | ||
var prevOffset_1 = -10; | ||
_this.setMinimumHeight(contentView, anchoredRow, Platform.screen.mainScreen.heightDIPs); | ||
utilities_1.ParallaxUtilities.setMinimumHeight(contentView, anchoredRow, Platform.screen.mainScreen.heightDIPs, _this._includesAnchored); | ||
app.on(app.orientationChangedEvent, function (args) { | ||
_this.setMinimumHeight(contentView, anchoredRow, _this._minimumHeights[args.newValue]); | ||
utilities_1.ParallaxUtilities.setMinimumHeight(contentView, anchoredRow, _this._minimumHeights[args.newValue], _this._includesAnchored); | ||
}); | ||
scrollView.on(scroll_view_1.ScrollView.scrollEvent, function (args) { | ||
if (_this._includesAnchored) { | ||
anchoredRow.marginTop = _this.getAnchoredTopHeight(maxTopViewHeight, scrollView.verticalOffset); | ||
anchoredRow.translateY = utilities_1.ParallaxUtilities.getAnchoredTopHeight(maxTopViewHeight, scrollView.verticalOffset); | ||
} | ||
headerView.height = _this.getTopViewHeight(maxTopViewHeight, scrollView.verticalOffset); | ||
_this.fadeViews(maxTopViewHeight, scrollView.verticalOffset, viewsToFade); | ||
headerView.height = utilities_1.ParallaxUtilities.getTopViewHeight(maxTopViewHeight, scrollView.verticalOffset); | ||
utilities_1.ParallaxUtilities.fadeViews(maxTopViewHeight, scrollView.verticalOffset, viewsToFade, _this._topOpacity); | ||
if (prevOffset_1 <= scrollView.verticalOffset) { | ||
@@ -226,96 +220,2 @@ } | ||
}); | ||
ParallaxView.prototype.setMinimumHeight = function (contentView, anchoredRow, minHeight) { | ||
if (this._includesAnchored) { | ||
minHeight = minHeight - (anchoredRow.height * 0.9); | ||
} | ||
contentView.minHeight = minHeight; | ||
}; | ||
ParallaxView.prototype.getMinimumHeights = function () { | ||
var height1 = Platform.screen.mainScreen.heightDIPs; | ||
var height2 = Platform.screen.mainScreen.widthDIPs; | ||
if (height1 > height2) { | ||
return { | ||
portrait: height1, | ||
landscape: height2 | ||
}; | ||
} | ||
else { | ||
return { | ||
portrait: height2, | ||
landscape: height1 | ||
}; | ||
} | ||
}; | ||
ParallaxView.prototype.addDropShadow = function (marginTop, width) { | ||
var wrapper = new stack_layout_1.StackLayout(); | ||
wrapper.width = width; | ||
wrapper.height = 3; | ||
wrapper.marginTop = marginTop; | ||
wrapper.addChild(this.shadowView(0.4, width)); | ||
wrapper.addChild(this.shadowView(0.2, width)); | ||
wrapper.addChild(this.shadowView(0.05, width)); | ||
return wrapper; | ||
}; | ||
ParallaxView.prototype.shadowView = function (opacity, width) { | ||
var shadowRow = new stack_layout_1.StackLayout(); | ||
shadowRow.backgroundColor = new color_1.Color('black'); | ||
shadowRow.opacity = opacity; | ||
shadowRow.height = 1; | ||
return shadowRow; | ||
}; | ||
ParallaxView.prototype.fadeViews = function (topHeight, verticalOffset, viewsToFade) { | ||
var _this = this; | ||
if (verticalOffset < topHeight) { | ||
this._topOpacity = parseFloat((1 - (verticalOffset * 0.01)).toString()); | ||
if (this._topOpacity > 0 && this._topOpacity <= 1) { | ||
viewsToFade.forEach(function (view) { | ||
view.opacity = _this._topOpacity; | ||
}); | ||
} | ||
} | ||
}; | ||
ParallaxView.prototype.getAnchoredTopHeight = function (topHeight, verticalOffset) { | ||
var marginTop; | ||
if (verticalOffset <= topHeight) { | ||
marginTop = topHeight - (verticalOffset * 2); | ||
if (marginTop > topHeight) { | ||
marginTop = topHeight; | ||
} | ||
if (app.android) { | ||
marginTop = marginTop - 5; | ||
} | ||
} | ||
else { | ||
marginTop = 0; | ||
} | ||
if (marginTop < 0) { | ||
marginTop = 0; | ||
} | ||
return marginTop; | ||
}; | ||
ParallaxView.prototype.getTopViewHeight = function (topHeight, verticalOffset) { | ||
if ((topHeight - verticalOffset) >= 0) { | ||
return topHeight - verticalOffset; | ||
} | ||
else { | ||
return 0; | ||
} | ||
}; | ||
ParallaxView.prototype.displayDevWarning = function (message) { | ||
var viewsToCollapse = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
viewsToCollapse[_i - 1] = arguments[_i]; | ||
} | ||
var warningText = new label_1.Label(); | ||
warningText.text = message; | ||
warningText.color = new color_1.Color('red'); | ||
warningText.textWrap = true; | ||
warningText.marginTop = 50; | ||
this.addChild(warningText); | ||
viewsToCollapse.forEach(function (view) { | ||
if (view != null) { | ||
view.visibility = 'collapse'; | ||
} | ||
}); | ||
}; | ||
return ParallaxView; | ||
@@ -322,0 +222,0 @@ }(grid_layout_1.GridLayout)); |
{ | ||
"name": "nativescript-parallax", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "NativeScript Parallax View Plugin.", | ||
@@ -20,3 +20,3 @@ "main": "nativescript-parallax.js", | ||
"preparedemo": "npm run build && cd demo && tns plugin remove nativescript-parallax && tns plugin add .. && tns install", | ||
"setup": "cd demo && npm install && cd .. && npm run build && cd demo && tns plugin add .. && cd .." | ||
"setup": "npm install && cd demo && npm install && cd .. && npm run build && cd demo && tns plugin add .. && cd .." | ||
}, | ||
@@ -23,0 +23,0 @@ "repository": { |
@@ -18,3 +18,3 @@ #NativeScript Parallax View Plugin for Android & iOS. | ||
<parallax:ParallaxView controlsToFade="headerLabel,headerLabel2"> | ||
<parallax:Header class="header-template"> | ||
<parallax:Header class="header-template" dropShadow="true"> | ||
<Label id="headerLabel" text="Parallax"></Label> | ||
@@ -21,0 +21,0 @@ <Label id="headerLabel2" text="Component"></Label> |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
15776574
17
42343
1