Classes
View
This class is the base class for all UI components.
A View occupies a rectangular area on the screen and is responsible for drawing and layouting of all UI components within.
Summary β
Constructors
Properties
- _androidContentDescriptionUpdated
- accessibilityBlurEvent
- accessibilityFocusChangedEvent
- accessibilityFocusEvent
- accessibilityHidden
- accessibilityHint
- accessibilityIdentifier
- accessibilityLabel
- accessibilityLanguage
- accessibilityLiveRegion
- accessibilityMediaSession
- accessibilityRole
- accessibilityState
- accessibilityValue
- accessible
- android
- androidDynamicElevationOffset
- androidElevation
- automationText
- background
- backgroundColor
- backgroundImage
- bindingContext
- borderBottomColor
- borderBottomLeftRadius
- borderBottomRightRadius
- borderBottomWidth
- borderColor
- borderLeftColor
- borderLeftWidth
- borderRadius
- borderRightColor
- borderRightWidth
- borderTopColor
- borderTopLeftRadius
- borderTopRightRadius
- borderTopWidth
- borderWidth
- boxShadow
- color
- cssClasses
- cssPseudoClasses
- cssType
- height
- horizontalAlignment
- ios
- iosAccessibilityAdjustsFontSize
- iosAccessibilityMaxFontScale
- iosAccessibilityMinFontScale
- iosIgnoreSafeArea
- iosOverflowSafeArea
- iosOverflowSafeAreaEnabled
- isEnabled
- isLayoutValid
- isUserInteractionEnabled
- layoutChangedEvent
- margin
- marginBottom
- marginLeft
- marginRight
- marginTop
- minHeight
- minWidth
- modal
- opacity
- originX
- originY
- perspective
- rotate
- rotateX
- rotateY
- scaleX
- scaleY
- showingModallyEvent
- shownModallyEvent
- translateX
- translateY
- verticalAlignment
- visibility
- width
74 properties inherited from ViewCommon
Click to expand
- _automaticallyAdjustsScrollViewInsets
- _closeModalCallback
- _context
- _cssState
- _defaultPaddingBottom
- _defaultPaddingLeft
- _defaultPaddingRight
- _defaultPaddingTop
- _domId
- _ignoreFlexMinWidthHeightReset
- _isAddedToNativeVisualTree
- _isLayoutValid
- _isPaddingRelative
- _isStyleScopeHost
- _oldBottom
- _oldLeft
- _oldRight
- _oldTop
- _styleScope
- _suspendNativeUpdatesCount
- accessibilityPerformEscapeEvent
- alignSelf
- className
- col
- colSpan
- column
- columnSpan
- createdEvent
- disposeNativeViewEvent
- dock
- domNode
- effectiveBorderBottomWidth
- effectiveBorderLeftWidth
- effectiveBorderRightWidth
- effectiveBorderTopWidth
- effectiveHeight
- effectiveLeft
- effectiveMarginBottom
- effectiveMarginLeft
- effectiveMarginRight
- effectiveMarginTop
- effectiveMinHeight
- effectiveMinWidth
- effectivePaddingBottom
- effectivePaddingLeft
- effectivePaddingRight
- effectivePaddingTop
- effectiveTop
- effectiveWidth
- flexGrow
- flexShrink
- flexWrapBefore
- id
- ignoreTouchAnimation
- isCollapsed
- left
- loadedEvent
- nativeViewProtected
- order
- parent
- propertyChangeEvent
- recycleNativeView
- reusable
- row
- rowSpan
- sharedTransitionIgnore
- sharedTransitionTag
- testID
- top
- touchAnimation
- touchDelay
- transitionId
- unloadedEvent
- viewController
Methods
- _closeAllModalViewsInternal
- _eachLayoutView
- _getNativeViewsCount
- _getRootModalViews
- _getValue
- _handleLivesync
- _hasAncestorView
- _onAttachedToWindow
- _onDetachedFromWindow
- _onSizeChanged
- _setValue
- _updateStyleScope
- accessibilityAnnouncement
- accessibilityScreenChanged
- animate
- combineMeasuredStates
- createAnimation
- eachChildView
- focus
- getActualSize
- getGestureObservers
- getLocationInWindow
- getLocationOnScreen
- getLocationRelativeTo
- getMeasuredHeight
- getMeasuredState
- getMeasuredWidth
- getSafeAreaInsets
- hasGestureObservers
- layout
- layoutChild
- layoutNativeView
- measure
- measureChild
- off
- on
- onBackPressed
- onLayout
- onMeasure
- resolveSizeAndState
- sendAccessibilityEvent
- setMeasuredDimension
- setOnTouchListener
69 methods inherited from ViewCommon
Click to expand
- _addView
- _addViewCore
- _addViewToNativeVisualTree
- _applyXmlAttribute
- _batchUpdate
- _childIndexToNativeChildIndex
- _createPropertyChangeData
- _dialogClosed
- _emit
- _hideNativeModalView
- _inheritStyleScope
- _layoutParent
- _observe
- _onRootViewReset
- _parentChanged
- _raiseLayoutChangedEvent
- _raiseShowingModallyEvent
- _raiseShownModallyEvent
- _removeView
- _removeViewCore
- _removeViewFromNativeVisualTree
- _resumeNativeUpdates
- _setupAsRootView
- _setupUI
- _shouldDelayLayout
- _showNativeModalView
- _suspendNativeUpdates
- _tearDownUI
- addEventListener
- addEventListener
- addPseudoClass
- bind
- callLoaded
- callUnloaded
- closeModal
- createNativeView
- deletePseudoClass
- destroyNode
- disposeNativeView
- eachChild
- ensureDomNode
- get
- getViewByDomId
- getViewById
- hasListeners
- initNativeView
- loadView
- notify
- notifyPropertyChange
- off
- on
- once
- once
- onLoaded
- onResumeNativeUpdates
- onUnloaded
- removeEventListener
- removeEventListener
- requestLayout
- resetNativeView
- set
- setInlineStyle
- setNativeView
- setProperty
- setTestID
- showModal
- toString
- unbind
- unloadView
Constructors β
Properties β
_androidContentDescriptionUpdated β
Internal use only. This is used to limit the number of updates to android.view.View.setContentDescription()
accessibilityHidden β
accessibilityHidden: boolean
Hide the view and its children from the a11y service
accessibilityHint β
A hint describes the elements behavior. Example: 'Tap change playback speed'
accessibilityIdentifier β
The view's unique accessibilityIdentifier.
This is used for automated testing.
accessibilityLabel β
Short description of the element, ideally one word.
accessibilityLanguage β
Sets the language in which to speak the element's label and value.
Accepts language ID tags that follows the "BCP 47" specification.
accessibilityLiveRegion β
accessibilityLiveRegion: AccessibilityLiveRegion
accessibilityMediaSession β
This view starts a media session. Equivalent to trait = startsMedia
accessibilityRole β
accessibilityRole: AccessibilityRole
Which role should this view be treated by the a11y service?
accessibilityState β
accessibilityState: AccessibilityState
Which state should this view be treated as by the a11y service?
accessibilityValue β
Current value of the element in a localized string.
accessible β
If
`true`
the element is an accessibility element and all the children will be treated as a single selectable component.android β
Gets the android-specific native instance that lies behind this proxy. Will be available if running on an Android platform.
androidDynamicElevationOffset β
Gets or sets the dynamic elevation offset of the android view.
androidElevation β
Gets or sets the elevation of the android view.
automationText β
background β
Gets or sets the background style property.
backgroundImage β
Gets or sets the background image of the view.
bindingContext β
Gets or sets the binding context of this instance. This object is used as a source for each Binding that does not have a source object specified.
borderBottomLeftRadius β
borderBottomLeftRadius: LengthType
Gets or sets the bottom left border radius of the view.
borderBottomRightRadius β
borderBottomRightRadius: LengthType
Gets or sets the bottom right border radius of the view.
borderBottomWidth β
borderBottomWidth: LengthType
Gets or sets the bottom border width of the view.
borderLeftWidth β
borderLeftWidth: LengthType
Gets or sets the left border width of the view.
borderRadius β
borderRadius: string | number | LengthDipUnit | LengthPxUnit
Gets or sets the border radius of the view.
borderRightWidth β
borderRightWidth: LengthType
Gets or sets the right border width of the view.
borderTopLeftRadius β
borderTopLeftRadius: LengthType
Gets or sets the top left border radius of the view.
borderTopRightRadius β
borderTopRightRadius: LengthType
Gets or sets the top right border radius of the view.
borderTopWidth β
borderTopWidth: LengthType
Gets or sets the top border width of the view.
borderWidth β
borderWidth: string | number | LengthDipUnit | LengthPxUnit
Gets or sets the border width of the view.
boxShadow β
Gets or sets the box shadow of the view.
cssClasses β
cssPseudoClasses β
cssType β
Gets the CSS fully qualified type name.
Using this as element type should allow for PascalCase and kebap-case selectors, when fully qualified, to match the element.
height β
height: PercentLengthType
Gets or sets the desired height of the view.
horizontalAlignment β
horizontalAlignment: HorizontalAlignmentType
Gets or sets the alignment of this view within its parent along the Horizontal axis.
ios β
Gets the ios-specific native instance that lies behind this proxy. Will be available if running on an iOS platform.
iosAccessibilityAdjustsFontSize β
Defines whether accessibility font scale should affect font size.
iosAccessibilityMaxFontScale β
Gets or sets the maximum accessibility font scale.
iosAccessibilityMinFontScale β
Gets or sets the minimum accessibility font scale.
iosIgnoreSafeArea β
Gets or sets a value indicating whether the the view should totally ignore safe areas computation. This property is iOS specific. Default value: false
iosOverflowSafeArea β
Instruct container view to expand beyond the safe area. This property is iOS specific. Default value: false
iosOverflowSafeAreaEnabled β
Enables or disables the iosOverflowSafeArea property for all children. This property is iOS specific. Default value: true
isEnabled β
Gets or sets a value indicating whether the the view is enabled. This affects the appearance of the view.
isLayoutValid β
Gets is layout is valid. This is a read-only property.
isUserInteractionEnabled β
Gets or sets a value indicating whether the user can interact with the view. This does not affect the appearance of the view.
margin β
margin: string | number | LengthDipUnit | LengthPxUnit | LengthPercentUnit
Gets or sets margin style property.
marginBottom β
marginBottom: PercentLengthType
Specifies extra space on the bottom side of this view.
marginLeft β
marginLeft: PercentLengthType
Specifies extra space on the left side of this view.
marginRight β
marginRight: PercentLengthType
Specifies extra space on the right side of this view.
marginTop β
marginTop: PercentLengthType
Specifies extra space on the top side of this view.
minHeight β
minHeight: LengthType
Gets or sets the minimum height the view may grow to.
minWidth β
minWidth: LengthType
Gets or sets the minimum width the view may grow to.
modal β
modal: View
Returns the current modal view that this page is showing (is parent of), if any.
opacity β
Gets or sets the opacity style property.
originX β
Gets or sets the X component of the origin point around which the view will be transformed. The default value is 0.5 representing the center of the view.
originY β
Gets or sets the Y component of the origin point around which the view will be transformed. The default value is 0.5 representing the center of the view.
perspective β
Gets or sets the distance of the camera form the view perspective.
Usually needed when rotating the view over the X or Y axis.
rotate β
Gets or sets the rotate affine transform of the view along the Z axis.
rotateX β
Gets or sets the rotate affine transform of the view along the X axis.
rotateY β
Gets or sets the rotate affine transform of the view along the Y axis.
scaleX β
Gets or sets the scaleX affine transform of the view.
scaleY β
Gets or sets the scaleY affine transform of the view.
translateX β
Gets or sets the translateX affine transform of the view in device independent pixels.
translateY β
Gets or sets the translateY affine transform of the view in device independent pixels.
verticalAlignment β
verticalAlignment: VerticalAlignmentType
Gets or sets the alignment of this view within its parent along the Vertical axis.
visibility β
visibility: VisibilityType
Gets or sets the visibility of the view.
width β
width: PercentLengthType
Gets or sets the desired width of the view.
accessibilityBlurEvent β
Static
String value used when hooking to accessibilityBlur event.
accessibilityFocusChangedEvent β
Static
String value used when hooking to accessibilityFocusChanged event.
accessibilityFocusEvent β
Static
String value used when hooking to accessibilityFocus event.
layoutChangedEvent β
Static
String value used when hooking to layoutChanged event.
showingModallyEvent β
Static
String value used when hooking to showingModally event.
shownModallyEvent β
Static
String value used when hooking to shownModally event.
Methods β
_closeAllModalViewsInternal β
Internal method:
Closes all modal views. Should be used by plugins like
`nativescript-angular`
which implement their own `modal views`
service. Returns boolean
_eachLayoutView β
Parameter Default Description
callback
(View: any) => void
Returns void
_getNativeViewsCount β
Returns number
_getRootModalViews β
_getValue β
__Obsolete:__ There is a new property system that does not rely on _getValue.
Parameter Default Description
property
any
Returns never
_handleLivesync β
Parameter Default Description
context
{
path: string
}
Returns boolean
_hasAncestorView β
_hasAncestorView(ancestorView: View): boolean
Checks whether the current view has specific view for an ancestor.
Parameter Default Description
ancestorView
Returns boolean
_onAttachedToWindow β
Called in android when native view is attached to window.
Returns void
_onDetachedFromWindow β
Called in android when native view is dettached from window.
Returns void
_onSizeChanged β
iOS Only Internal method used to update various view details like background rerendering, border, etc.
Returns void
_setValue β
__Obsolete:__ There is a new property system that does not rely on _setValue.
Parameter Default Description
property
any
value
any
Returns never
_updateStyleScope β
Updates styleScope or create new styleScope.
Parameter Default Description
cssFileName
string
cssString
string
css
string
Returns void
accessibilityAnnouncement β
Make an announcement to the screen reader.
Parameter Default Description
msg
string
Returns void
accessibilityScreenChanged β
animate β
animate(options: AnimationDefinition): AnimationPromise
Animates one or more properties of the view based on the supplied options.
Parameter Default Description
options
Returns AnimationPromise
createAnimation β
createAnimation(options: AnimationDefinition): Animation
Creates an Animation object based on the supplied options.
Parameter Default Description
options
Returns Animation
eachChildView β
focus β
Tries to focus the view.
Returns a value indicating whether this view or one of its descendants actually took focus.
Returns boolean
getActualSize β
getGestureObservers β
getGestureObservers(type: GestureTypes): GesturesObserver[]
Parameter Default Description
type
Returns GesturesObserver[]
getLocationInWindow β
Returns the location of this view in the window coordinate system.
Returns Point
getLocationOnScreen β
Returns the location of this view in the screen coordinate system.
Returns Point
getLocationRelativeTo β
getLocationRelativeTo(otherView: View): Point
Returns the location of this view in the otherView's coordinate system.
Parameter Default Description
otherView
Returns Point
getMeasuredHeight β
Returns the raw height component.
Returns number
getMeasuredState β
Returns number
getMeasuredWidth β
Returns the raw width component.
Returns number
getSafeAreaInsets β
Returns the iOS safe area insets of this view.
Returns {
bottom: any
left: any
right: any
}
hasGestureObservers β
Android only check if gesture observers are attached
Returns boolean
layout β
Assign a size and position to a view and all of its descendants
This is the second phase of the layout mechanism. (The first is measuring). In this phase, each parent calls layout on all of its children to position them. This is typically done using the child measurements that were stored in the measure pass().
Derived classes should not override this method. Derived classes with children should override onLayout. In that method, they should call layout on each of their children.
Parameter Default Description
left
number
top
number
right
number
bottom
number
setFrame
boolean
Returns void
layoutNativeView β
Called from onLayout when native view position is about to be changed.
Parameter Default Description
left
number
Left position, relative to parent
top
number
Top position, relative to parent
right
number
Right position, relative to parent
bottom
number
Bottom position, relative to parent
Returns void
measure β
This is called to find out how big a view should be. The parent supplies constraint information in the width and height parameters.
The actual measurement work of a view is performed in onMeasure(int, int), called by this method. Therefore, only onMeasure(int, int) can and must be overridden by subclasses.
Parameter Default Description
widthMeasureSpec
number
Horizontal space requirements as imposed by the parent
heightMeasureSpec
number
Vertical space requirements as imposed by the parent
Returns void
off β
off(eventNames: string | GestureTypes, callback?: (args: EventData) => void, thisArg?: any): any
Removes listener(s) for the specified event name.
Parameter Default Description
eventNames
string | GestureTypes
Comma delimited names of the events or gesture types the specified listener is associated with.
callback
(args: EventData) => void
An optional parameter pointing to a specific listener. If not defined, all listeners for the event names will be removed.
thisArg
any
An optional parameter which when set will be used to refine search of the correct callback which will be removed as event listener.
Returns any
on β
on(eventNames: string | GestureTypes, callback: (args: EventData) => void, thisArg?: any): any
A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
Parameter Default Description
eventNames
string | GestureTypes
String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by
`,`
(e.g. "propertyChange", "change") or you can use gesture types.thisArg
any
An optional parameter which will be used as
`this`
context for callback execution. Returns any
on(event: "loaded", callback: (args: EventData) => void, thisArg?: any): any
Raised when a loaded event occurs.
Returns any
on(event: "unloaded", callback: (args: EventData) => void, thisArg?: any): any
Raised when an unloaded event occurs.
Returns any
on(event: "androidBackPressed", callback: (args: EventData) => void, thisArg?: any): any
Raised when a back button is pressed.
This event is raised only for android.
Parameter Default Description
event
"androidBackPressed"
callback
(args: EventData) => void
thisArg
any
Returns any
on(event: "showingModally", callback: (args: ShownModallyData) => void, thisArg?: any): void
Raised before the view is shown as a modal dialog.
Parameter Default Description
event
"showingModally"
callback
(args: ShownModallyData) => void
thisArg
any
Returns void
on(event: "shownModally", callback: (args: ShownModallyData) => void, thisArg?: any): any
Raised after the view is shown as a modal dialog.
Parameter Default Description
event
"shownModally"
callback
(args: ShownModallyData) => void
thisArg
any
Returns any
onBackPressed β
Derived classes can override this method to handle Android back button press.
Returns boolean
onLayout β
Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their children.
Parameter Default Description
left
number
Left position, relative to parent
top
number
Top position, relative to parent
right
number
Right position, relative to parent
bottom
number
Bottom position, relative to parent
Returns void
onMeasure β
Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overriden by subclasses to provide accurate and efficient measurement of their contents.
When overriding this method, you must call setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an exception, thrown by measure(int, int).
Parameter Default Description
widthMeasureSpec
number
horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
heightMeasureSpec
number
vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
Returns void
sendAccessibilityEvent β
Send accessibility event
Parameter Default Description
options
Partial<AccessibilityEventOptions>
Returns void
setMeasuredDimension β
This method must be called by onMeasure(int, int) to store the measured width and measured height. Failing to do so will trigger an exception at measurement time.
Parameter Default Description
measuredWidth
number
The measured width of this view. May be a complex bit mask as defined by MEASURED_SIZE_MASK and MEASURED_STATE_TOO_SMALL.
measuredHeight
number
The measured height of this view. May be a complex bit mask as defined by MEASURED_SIZE_MASK and MEASURED_STATE_TOO_SMALL.
Returns void
setOnTouchListener β
Android only to set the touch listener
Returns void
combineMeasuredStates β
Static
Parameter Default Description
curState
number
newState
any
Returns number
layoutChild β
Static
measureChild β
Static
resolveSizeAndState β
Static
resolveSizeAndState(
size: number,
specSize: number,
specMode: number,
childMeasuredState: number
): number
Utility to reconcile a desired size and state, with constraints imposed
by a MeasureSpec. Will take the desired size, unless a different size
is imposed by the constraints. The returned value is a compound integer,
with the resolved size in the MEASURED_SIZE_MASK bits and
optionally the bit MEASURED_STATE_TOO_SMALL set if the resulting
size is smaller than the size the view wants to be.
Parameter Default Description
size
number
specSize
number
specMode
number
childMeasuredState
number
Returns number
- Previous
- Transition
- Next
- ViewBase
On this page
- Summary
- Constructors
- Properties
- _androidContentDescriptionUpdated
- accessibilityHidden
- accessibilityHint
- accessibilityIdentifier
- accessibilityLabel
- accessibilityLanguage
- accessibilityLiveRegion
- accessibilityMediaSession
- accessibilityRole
- accessibilityState
- accessibilityValue
- accessible
- android
- androidDynamicElevationOffset
- androidElevation
- automationText
- background
- backgroundColor
- backgroundImage
- bindingContext
- borderBottomColor
- borderBottomLeftRadius
- borderBottomRightRadius
- borderBottomWidth
- borderColor
- borderLeftColor
- borderLeftWidth
- borderRadius
- borderRightColor
- borderRightWidth
- borderTopColor
- borderTopLeftRadius
- borderTopRightRadius
- borderTopWidth
- borderWidth
- boxShadow
- color
- cssClasses
- cssPseudoClasses
- cssType
- height
- horizontalAlignment
- ios
- iosAccessibilityAdjustsFontSize
- iosAccessibilityMaxFontScale
- iosAccessibilityMinFontScale
- iosIgnoreSafeArea
- iosOverflowSafeArea
- iosOverflowSafeAreaEnabled
- isEnabled
- isLayoutValid
- isUserInteractionEnabled
- margin
- marginBottom
- marginLeft
- marginRight
- marginTop
- minHeight
- minWidth
- modal
- opacity
- originX
- originY
- perspective
- rotate
- rotateX
- rotateY
- scaleX
- scaleY
- translateX
- translateY
- verticalAlignment
- visibility
- width
- accessibilityBlurEvent
- accessibilityFocusChangedEvent
- accessibilityFocusEvent
- layoutChangedEvent
- showingModallyEvent
- shownModallyEvent
- Methods
- _closeAllModalViewsInternal
- _eachLayoutView
- _getNativeViewsCount
- _getRootModalViews
- _getValue
- _handleLivesync
- _hasAncestorView
- _onAttachedToWindow
- _onDetachedFromWindow
- _onSizeChanged
- _setValue
- _updateStyleScope
- accessibilityAnnouncement
- accessibilityScreenChanged
- animate
- createAnimation
- eachChildView
- focus
- getActualSize
- getGestureObservers
- getLocationInWindow
- getLocationOnScreen
- getLocationRelativeTo
- getMeasuredHeight
- getMeasuredState
- getMeasuredWidth
- getSafeAreaInsets
- hasGestureObservers
- layout
- layoutNativeView
- measure
- off
- on
- onBackPressed
- onLayout
- onMeasure
- sendAccessibilityEvent
- setMeasuredDimension
- setOnTouchListener
- combineMeasuredStates
- layoutChild
- measureChild
- resolveSizeAndState