| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | import { ButtonBase } from './button-common'; | |
| 2 | 2 | import { PseudoClassHandler } from '../core/view'; | |
| 3 | - import { zIndexProperty, minWidthProperty, minHeightProperty, paddingInternalProperty } from '../styling/style-properties'; | ||
| 3 | + import { zIndexProperty, minWidthProperty, minHeightProperty, paddingInternalProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty, _hasPaddingSetNativeOverrides } from '../styling/style-properties'; | ||
| 4 | 4 | import { Length } from '../styling/length-shared'; | |
| 5 | 5 | import { textAlignmentProperty } from '../text-base'; | |
| 6 | 6 | import { CoreTypes } from '../../core-types'; | |
@@ -123,12 +123,78 @@ export class Button extends ButtonBase { | |||
| 123 | 123 | return { value: dips, unit: 'px' }; | |
| 124 | 124 | } | |
| 125 | 125 | ||
| 126 | + // When no subclass overrides the per-side handlers, they stage into | ||
| 127 | + // _pendingPadding - which only exists while [paddingInternalProperty.setNative] | ||
| 128 | + // runs - and all sides commit in one native write. An override takes ownership: | ||
| 129 | + // the consolidated write stands down and each side applies individually, so an | ||
| 130 | + // override that does not chain to super suppresses that side entirely. | ||
| 131 | + private _pendingPadding: { top: number; right: number; bottom: number; left: number }; | ||
| 132 | + | ||
| 133 | + [paddingTopProperty.getDefault](): CoreTypes.LengthType { | ||
| 134 | + return { value: this._defaultPaddingTop, unit: 'px' }; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + [paddingTopProperty.setNative](value: CoreTypes.LengthType) { | ||
| 138 | + const padding = Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderTopWidth, 0); | ||
| 139 | + if (this._pendingPadding) { | ||
| 140 | + this._pendingPadding.top = padding; | ||
| 141 | + } else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) { | ||
| 142 | + org.nativescript.widgets.ViewHelper.setPaddingTop(this.nativeViewProtected, padding); | ||
| 143 | + } | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + [paddingRightProperty.getDefault](): CoreTypes.LengthType { | ||
| 147 | + return { value: this._defaultPaddingRight, unit: 'px' }; | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + [paddingRightProperty.setNative](value: CoreTypes.LengthType) { | ||
| 151 | + const padding = Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderRightWidth, 0); | ||
| 152 | + if (this._pendingPadding) { | ||
| 153 | + this._pendingPadding.right = padding; | ||
| 154 | + } else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) { | ||
| 155 | + org.nativescript.widgets.ViewHelper.setPaddingRight(this.nativeViewProtected, padding); | ||
| 156 | + } | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + [paddingBottomProperty.getDefault](): CoreTypes.LengthType { | ||
| 160 | + return { value: this._defaultPaddingBottom, unit: 'px' }; | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + [paddingBottomProperty.setNative](value: CoreTypes.LengthType) { | ||
| 164 | + const padding = Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderBottomWidth, 0); | ||
| 165 | + if (this._pendingPadding) { | ||
| 166 | + this._pendingPadding.bottom = padding; | ||
| 167 | + } else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) { | ||
| 168 | + org.nativescript.widgets.ViewHelper.setPaddingBottom(this.nativeViewProtected, padding); | ||
| 169 | + } | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + [paddingLeftProperty.getDefault](): CoreTypes.LengthType { | ||
| 173 | + return { value: this._defaultPaddingLeft, unit: 'px' }; | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + [paddingLeftProperty.setNative](value: CoreTypes.LengthType) { | ||
| 177 | + const padding = Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderLeftWidth, 0); | ||
| 178 | + if (this._pendingPadding) { | ||
| 179 | + this._pendingPadding.left = padding; | ||
| 180 | + } else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) { | ||
| 181 | + org.nativescript.widgets.ViewHelper.setPaddingLeft(this.nativeViewProtected, padding); | ||
| 182 | + } | ||
| 183 | + } | ||
| 184 | + | ||
| 126 | 185 | [paddingInternalProperty.setNative](_value: string) { | |
| 127 | - const left = this.effectivePaddingLeft + Length.toDevicePixels(this.style.borderLeftWidth, 0); | ||
| 128 | - const top = this.effectivePaddingTop + Length.toDevicePixels(this.style.borderTopWidth, 0); | ||
| 129 | - const right = this.effectivePaddingRight + Length.toDevicePixels(this.style.borderRightWidth, 0); | ||
| 130 | - const bottom = this.effectivePaddingBottom + Length.toDevicePixels(this.style.borderBottomWidth, 0); | ||
| 131 | - this.nativeViewProtected.setPadding(left, top, right, bottom); | ||
| 186 | + if (_hasPaddingSetNativeOverrides(this, Button.prototype)) { | ||
| 187 | + // An override owns padding application; each side applies through its own handler. | ||
| 188 | + return; | ||
| 189 | + } | ||
| 190 | + const nativeView = this.nativeViewProtected; | ||
| 191 | + this._pendingPadding = { top: nativeView.getPaddingTop(), right: nativeView.getPaddingRight(), bottom: nativeView.getPaddingBottom(), left: nativeView.getPaddingLeft() }; | ||
| 192 | + (<any>this)[paddingTopProperty.setNative](this.style.paddingTop); | ||
| 193 | + (<any>this)[paddingRightProperty.setNative](this.style.paddingRight); | ||
| 194 | + (<any>this)[paddingBottomProperty.setNative](this.style.paddingBottom); | ||
| 195 | + (<any>this)[paddingLeftProperty.setNative](this.style.paddingLeft); | ||
| 196 | + nativeView.setPadding(this._pendingPadding.left, this._pendingPadding.top, this._pendingPadding.right, this._pendingPadding.bottom); | ||
| 197 | + this._pendingPadding = null; | ||
| 132 | 198 | } | |
| 133 | 199 | ||
| 134 | 200 | [zIndexProperty.setNative](value: number) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,7 @@ | |||
| 1 | 1 | import { ControlStateChangeListener } from '../core/control-state-change'; | |
| 2 | 2 | import { ButtonBase } from './button-common'; | |
| 3 | 3 | import { View, PseudoClassHandler } from '../core/view'; | |
| 4 | - import { borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty, directionProperty, paddingInternalProperty } from '../styling/style-properties'; | ||
| 4 | + import { borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty, directionProperty, paddingInternalProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty, _hasPaddingSetNativeOverrides } from '../styling/style-properties'; | ||
| 5 | 5 | import { textAlignmentProperty, whiteSpaceProperty, textOverflowProperty } from '../text-base'; | |
| 6 | 6 | import { layout } from '../../utils'; | |
| 7 | 7 | import { CoreTypes } from '../../core-types'; | |
@@ -147,13 +147,115 @@ export class Button extends ButtonBase { | |||
| 147 | 147 | }); | |
| 148 | 148 | } | |
| 149 | 149 | ||
| 150 | + // When no subclass overrides the per-side handlers, they stage into | ||
| 151 | + // _pendingPadding - which only exists while [paddingInternalProperty.setNative] | ||
| 152 | + // runs - and all sides commit in one native write. An override takes ownership: | ||
| 153 | + // the consolidated write stands down and each side applies individually, so an | ||
| 154 | + // override that does not chain to super suppresses that side entirely. | ||
| 155 | + private _pendingPadding: { top: number; right: number; bottom: number; left: number }; | ||
| 156 | + | ||
| 157 | + [paddingTopProperty.getDefault](): CoreTypes.LengthType { | ||
| 158 | + return { | ||
| 159 | + value: this.nativeViewProtected.contentEdgeInsets.top, | ||
| 160 | + unit: 'px', | ||
| 161 | + }; | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + [paddingTopProperty.setNative](_value: CoreTypes.LengthType) { | ||
| 165 | + if (this._pendingPadding) { | ||
| 166 | + this._pendingPadding.top = layout.toDeviceIndependentPixels(this.effectivePaddingTop + this.effectiveBorderTopWidth); | ||
| 167 | + } else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) { | ||
| 168 | + const nativeView = this.nativeViewProtected; | ||
| 169 | + const inset = nativeView.contentEdgeInsets; | ||
| 170 | + nativeView.contentEdgeInsets = new UIEdgeInsets({ | ||
| 171 | + top: layout.toDeviceIndependentPixels(this.effectivePaddingTop + this.effectiveBorderTopWidth), | ||
| 172 | + right: inset.right, | ||
| 173 | + bottom: inset.bottom, | ||
| 174 | + left: inset.left, | ||
| 175 | + }); | ||
| 176 | + } | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + [paddingRightProperty.getDefault](): CoreTypes.LengthType { | ||
| 180 | + return { | ||
| 181 | + value: this.nativeViewProtected.contentEdgeInsets.right, | ||
| 182 | + unit: 'px', | ||
| 183 | + }; | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + [paddingRightProperty.setNative](_value: CoreTypes.LengthType) { | ||
| 187 | + if (this._pendingPadding) { | ||
| 188 | + this._pendingPadding.right = layout.toDeviceIndependentPixels(this.effectivePaddingRight + this.effectiveBorderRightWidth); | ||
| 189 | + } else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) { | ||
| 190 | + const nativeView = this.nativeViewProtected; | ||
| 191 | + const inset = nativeView.contentEdgeInsets; | ||
| 192 | + nativeView.contentEdgeInsets = new UIEdgeInsets({ | ||
| 193 | + top: inset.top, | ||
| 194 | + right: layout.toDeviceIndependentPixels(this.effectivePaddingRight + this.effectiveBorderRightWidth), | ||
| 195 | + bottom: inset.bottom, | ||
| 196 | + left: inset.left, | ||
| 197 | + }); | ||
| 198 | + } | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + [paddingBottomProperty.getDefault](): CoreTypes.LengthType { | ||
| 202 | + return { | ||
| 203 | + value: this.nativeViewProtected.contentEdgeInsets.bottom, | ||
| 204 | + unit: 'px', | ||
| 205 | + }; | ||
| 206 | + } | ||
| 207 | + | ||
| 208 | + [paddingBottomProperty.setNative](_value: CoreTypes.LengthType) { | ||
| 209 | + if (this._pendingPadding) { | ||
| 210 | + this._pendingPadding.bottom = layout.toDeviceIndependentPixels(this.effectivePaddingBottom + this.effectiveBorderBottomWidth); | ||
| 211 | + } else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) { | ||
| 212 | + const nativeView = this.nativeViewProtected; | ||
| 213 | + const inset = nativeView.contentEdgeInsets; | ||
| 214 | + nativeView.contentEdgeInsets = new UIEdgeInsets({ | ||
| 215 | + top: inset.top, | ||
| 216 | + right: inset.right, | ||
| 217 | + bottom: layout.toDeviceIndependentPixels(this.effectivePaddingBottom + this.effectiveBorderBottomWidth), | ||
| 218 | + left: inset.left, | ||
| 219 | + }); | ||
| 220 | + } | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | + [paddingLeftProperty.getDefault](): CoreTypes.LengthType { | ||
| 224 | + return { | ||
| 225 | + value: this.nativeViewProtected.contentEdgeInsets.left, | ||
| 226 | + unit: 'px', | ||
| 227 | + }; | ||
| 228 | + } | ||
| 229 | + | ||
| 230 | + [paddingLeftProperty.setNative](_value: CoreTypes.LengthType) { | ||
| 231 | + if (this._pendingPadding) { | ||
| 232 | + this._pendingPadding.left = layout.toDeviceIndependentPixels(this.effectivePaddingLeft + this.effectiveBorderLeftWidth); | ||
| 233 | + } else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) { | ||
| 234 | + const nativeView = this.nativeViewProtected; | ||
| 235 | + const inset = nativeView.contentEdgeInsets; | ||
| 236 | + nativeView.contentEdgeInsets = new UIEdgeInsets({ | ||
| 237 | + top: inset.top, | ||
| 238 | + right: inset.right, | ||
| 239 | + bottom: inset.bottom, | ||
| 240 | + left: layout.toDeviceIndependentPixels(this.effectivePaddingLeft + this.effectiveBorderLeftWidth), | ||
| 241 | + }); | ||
| 242 | + } | ||
| 243 | + } | ||
| 244 | + | ||
| 150 | 245 | [paddingInternalProperty.setNative](_value: string) { | |
| 151 | - this.nativeViewProtected.contentEdgeInsets = new UIEdgeInsets({ | ||
| 152 | - top: layout.toDeviceIndependentPixels(this.effectivePaddingTop + this.effectiveBorderTopWidth), | ||
| 153 | - left: layout.toDeviceIndependentPixels(this.effectivePaddingLeft + this.effectiveBorderLeftWidth), | ||
| 154 | - bottom: layout.toDeviceIndependentPixels(this.effectivePaddingBottom + this.effectiveBorderBottomWidth), | ||
| 155 | - right: layout.toDeviceIndependentPixels(this.effectivePaddingRight + this.effectiveBorderRightWidth), | ||
| 156 | - }); | ||
| 246 | + if (_hasPaddingSetNativeOverrides(this, Button.prototype)) { | ||
| 247 | + // An override owns padding application; each side applies through its own handler. | ||
| 248 | + return; | ||
| 249 | + } | ||
| 250 | + const nativeView = this.nativeViewProtected; | ||
| 251 | + const inset = nativeView.contentEdgeInsets; | ||
| 252 | + this._pendingPadding = { top: inset.top, right: inset.right, bottom: inset.bottom, left: inset.left }; | ||
| 253 | + (<any>this)[paddingTopProperty.setNative](this.style.paddingTop); | ||
| 254 | + (<any>this)[paddingRightProperty.setNative](this.style.paddingRight); | ||
| 255 | + (<any>this)[paddingBottomProperty.setNative](this.style.paddingBottom); | ||
| 256 | + (<any>this)[paddingLeftProperty.setNative](this.style.paddingLeft); | ||
| 257 | + nativeView.contentEdgeInsets = new UIEdgeInsets(this._pendingPadding); | ||
| 258 | + this._pendingPadding = null; | ||
| 157 | 259 | } | |
| 158 | 260 | ||
| 159 | 261 | [textAlignmentProperty.setNative](value: CoreTypes.TextAlignmentType) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | import { Label as LabelDefinition } from '.'; | |
| 2 | 2 | import { Background } from '../styling/background'; | |
| 3 | - import { borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty, directionProperty, paddingInternalProperty } from '../styling/style-properties'; | ||
| 3 | + import { borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty, directionProperty, paddingInternalProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty, _hasPaddingSetNativeOverrides } from '../styling/style-properties'; | ||
| 4 | 4 | import { booleanConverter } from '../core/view-base'; | |
| 5 | 5 | import { View, CSSType } from '../core/view'; | |
| 6 | 6 | import { CoreTypes } from '../../core-types'; | |
@@ -228,13 +228,87 @@ export class Label extends TextBase implements LabelDefinition { | |||
| 228 | 228 | }); | |
| 229 | 229 | } | |
| 230 | 230 | ||
| 231 | + // When no subclass overrides the per-side handlers, they stage into | ||
| 232 | + // _pendingPadding - which only exists while [paddingInternalProperty.setNative] | ||
| 233 | + // runs - and all sides commit in one native write. An override takes ownership: | ||
| 234 | + // the consolidated write stands down and each side applies individually, so an | ||
| 235 | + // override that does not chain to super suppresses that side entirely. | ||
| 236 | + private _pendingPadding: { top: number; right: number; bottom: number; left: number }; | ||
| 237 | + | ||
| 238 | + [paddingTopProperty.setNative](_value: CoreTypes.LengthType) { | ||
| 239 | + if (this._pendingPadding) { | ||
| 240 | + this._pendingPadding.top = layout.toDeviceIndependentPixels(this.effectivePaddingTop); | ||
| 241 | + } else if (_hasPaddingSetNativeOverrides(this, Label.prototype)) { | ||
| 242 | + const nativeView = this.nativeTextViewProtected; | ||
| 243 | + const inset = nativeView.padding; | ||
| 244 | + nativeView.padding = new UIEdgeInsets({ | ||
| 245 | + top: layout.toDeviceIndependentPixels(this.effectivePaddingTop), | ||
| 246 | + right: inset.right, | ||
| 247 | + bottom: inset.bottom, | ||
| 248 | + left: inset.left, | ||
| 249 | + }); | ||
| 250 | + } | ||
| 251 | + } | ||
| 252 | + | ||
| 253 | + [paddingRightProperty.setNative](_value: CoreTypes.LengthType) { | ||
| 254 | + if (this._pendingPadding) { | ||
| 255 | + this._pendingPadding.right = layout.toDeviceIndependentPixels(this.effectivePaddingRight); | ||
| 256 | + } else if (_hasPaddingSetNativeOverrides(this, Label.prototype)) { | ||
| 257 | + const nativeView = this.nativeTextViewProtected; | ||
| 258 | + const inset = nativeView.padding; | ||
| 259 | + nativeView.padding = new UIEdgeInsets({ | ||
| 260 | + top: inset.top, | ||
| 261 | + right: layout.toDeviceIndependentPixels(this.effectivePaddingRight), | ||
| 262 | + bottom: inset.bottom, | ||
| 263 | + left: inset.left, | ||
| 264 | + }); | ||
| 265 | + } | ||
| 266 | + } | ||
| 267 | + | ||
| 268 | + [paddingBottomProperty.setNative](_value: CoreTypes.LengthType) { | ||
| 269 | + if (this._pendingPadding) { | ||
| 270 | + this._pendingPadding.bottom = layout.toDeviceIndependentPixels(this.effectivePaddingBottom); | ||
| 271 | + } else if (_hasPaddingSetNativeOverrides(this, Label.prototype)) { | ||
| 272 | + const nativeView = this.nativeTextViewProtected; | ||
| 273 | + const inset = nativeView.padding; | ||
| 274 | + nativeView.padding = new UIEdgeInsets({ | ||
| 275 | + top: inset.top, | ||
| 276 | + right: inset.right, | ||
| 277 | + bottom: layout.toDeviceIndependentPixels(this.effectivePaddingBottom), | ||
| 278 | + left: inset.left, | ||
| 279 | + }); | ||
| 280 | + } | ||
| 281 | + } | ||
| 282 | + | ||
| 283 | + [paddingLeftProperty.setNative](_value: CoreTypes.LengthType) { | ||
| 284 | + if (this._pendingPadding) { | ||
| 285 | + this._pendingPadding.left = layout.toDeviceIndependentPixels(this.effectivePaddingLeft); | ||
| 286 | + } else if (_hasPaddingSetNativeOverrides(this, Label.prototype)) { | ||
| 287 | + const nativeView = this.nativeTextViewProtected; | ||
| 288 | + const inset = nativeView.padding; | ||
| 289 | + nativeView.padding = new UIEdgeInsets({ | ||
| 290 | + top: inset.top, | ||
| 291 | + right: inset.right, | ||
| 292 | + bottom: inset.bottom, | ||
| 293 | + left: layout.toDeviceIndependentPixels(this.effectivePaddingLeft), | ||
| 294 | + }); | ||
| 295 | + } | ||
| 296 | + } | ||
| 297 | + | ||
| 231 | 298 | [paddingInternalProperty.setNative](_value: string) { | |
| 232 | - this.nativeTextViewProtected.padding = new UIEdgeInsets({ | ||
| 233 | - top: layout.toDeviceIndependentPixels(this.effectivePaddingTop), | ||
| 234 | - right: layout.toDeviceIndependentPixels(this.effectivePaddingRight), | ||
| 235 | - bottom: layout.toDeviceIndependentPixels(this.effectivePaddingBottom), | ||
| 236 | - left: layout.toDeviceIndependentPixels(this.effectivePaddingLeft), | ||
| 237 | - }); | ||
| 299 | + if (_hasPaddingSetNativeOverrides(this, Label.prototype)) { | ||
| 300 | + // An override owns padding application; each side applies through its own handler. | ||
| 301 | + return; | ||
| 302 | + } | ||
| 303 | + const nativeView = this.nativeTextViewProtected; | ||
| 304 | + const padding = nativeView.padding; | ||
| 305 | + this._pendingPadding = { top: padding.top, right: padding.right, bottom: padding.bottom, left: padding.left }; | ||
| 306 | + (<any>this)[paddingTopProperty.setNative](this.style.paddingTop); | ||
| 307 | + (<any>this)[paddingRightProperty.setNative](this.style.paddingRight); | ||
| 308 | + (<any>this)[paddingBottomProperty.setNative](this.style.paddingBottom); | ||
| 309 | + (<any>this)[paddingLeftProperty.setNative](this.style.paddingLeft); | ||
| 310 | + nativeView.padding = new UIEdgeInsets(this._pendingPadding); | ||
| 311 | + this._pendingPadding = null; | ||
| 238 | 312 | } | |
| 239 | 313 | } | |
| 240 | 314 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments