mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Use presenter state for scrollbars and scrollbar corner
This commit is contained in:
@@ -7,28 +7,33 @@ ScrollbarComponent = React.createClass
|
||||
displayName: 'ScrollbarComponent'
|
||||
|
||||
render: ->
|
||||
{orientation, className, scrollHeight, scrollWidth, visible} = @props
|
||||
{scrollableInOppositeDirection, horizontalScrollbarHeight, verticalScrollbarWidth} = @props
|
||||
{useHardwareAcceleration} = @props
|
||||
{presenter, orientation, className, useHardwareAcceleration} = @props
|
||||
|
||||
switch orientation
|
||||
when 'vertical'
|
||||
state = presenter.state.verticalScrollbar
|
||||
when 'horizontal'
|
||||
state = presenter.state.horizontalScrollbar
|
||||
|
||||
style = {}
|
||||
style.display = 'none' unless visible
|
||||
|
||||
style.display = 'none' unless state.visible
|
||||
style.transform = 'translateZ(0)' if useHardwareAcceleration # See atom/atom#3559
|
||||
switch orientation
|
||||
when 'vertical'
|
||||
style.width = verticalScrollbarWidth
|
||||
style.bottom = horizontalScrollbarHeight if scrollableInOppositeDirection
|
||||
style.width = state.width
|
||||
style.bottom = state.bottom
|
||||
when 'horizontal'
|
||||
style.left = 0
|
||||
style.right = verticalScrollbarWidth if scrollableInOppositeDirection
|
||||
style.height = horizontalScrollbarHeight
|
||||
style.right = state.right
|
||||
style.height = state.height
|
||||
|
||||
div {className, style},
|
||||
switch orientation
|
||||
when 'vertical'
|
||||
div className: 'scrollbar-content', style: {height: scrollHeight}
|
||||
div className: 'scrollbar-content', style: {height: presenter.state.scrollHeight}
|
||||
when 'horizontal'
|
||||
div className: 'scrollbar-content', style: {width: scrollWidth}
|
||||
div className: 'scrollbar-content', style: {width: presenter.state.content.scrollWidth}
|
||||
|
||||
componentDidMount: ->
|
||||
{orientation} = @props
|
||||
@@ -41,26 +46,15 @@ ScrollbarComponent = React.createClass
|
||||
componentWillUnmount: ->
|
||||
@getDOMNode().removeEventListener 'scroll', @onScroll
|
||||
|
||||
shouldComponentUpdate: (newProps) ->
|
||||
return true if newProps.visible isnt @props.visible
|
||||
|
||||
switch @props.orientation
|
||||
when 'vertical'
|
||||
not isEqualForProperties(newProps, @props, 'scrollHeight', 'scrollTop', 'scrollableInOppositeDirection', 'verticalScrollbarWidth')
|
||||
when 'horizontal'
|
||||
not isEqualForProperties(newProps, @props, 'scrollWidth', 'scrollLeft', 'scrollableInOppositeDirection', 'horizontalScrollbarHeight')
|
||||
|
||||
componentDidUpdate: ->
|
||||
{orientation, scrollTop, scrollLeft} = @props
|
||||
{orientation, presenter} = @props
|
||||
node = @getDOMNode()
|
||||
|
||||
switch orientation
|
||||
when 'vertical'
|
||||
node.scrollTop = scrollTop
|
||||
@props.scrollTop = node.scrollTop # Ensure scrollTop reflects actual DOM without triggering another update
|
||||
node.scrollTop = presenter.state.scrollTop
|
||||
when 'horizontal'
|
||||
node.scrollLeft = scrollLeft
|
||||
@props.scrollLeft = node.scrollLeft # Ensure scrollLeft reflects actual DOM without triggering another update
|
||||
node.scrollLeft = presenter.state.content.scrollLeft
|
||||
|
||||
onScroll: ->
|
||||
{orientation, onScroll} = @props
|
||||
@@ -69,9 +63,7 @@ ScrollbarComponent = React.createClass
|
||||
switch orientation
|
||||
when 'vertical'
|
||||
scrollTop = node.scrollTop
|
||||
@props.scrollTop = scrollTop # Ensure scrollTop reflects actual DOM without triggering another update
|
||||
onScroll(scrollTop)
|
||||
when 'horizontal'
|
||||
scrollLeft = node.scrollLeft
|
||||
@props.scrollLeft = scrollLeft # Ensure scrollLeft reflects actual DOM without triggering another update
|
||||
onScroll(scrollLeft)
|
||||
|
||||
@@ -7,7 +7,11 @@ ScrollbarCornerComponent = React.createClass
|
||||
displayName: 'ScrollbarCornerComponent'
|
||||
|
||||
render: ->
|
||||
{visible, measuringScrollbars, width, height} = @props
|
||||
{presenter, measuringScrollbars} = @props
|
||||
|
||||
visible = presenter.state.horizontalScrollbar.visible and presenter.state.verticalScrollbar.visible
|
||||
width = presenter.state.verticalScrollbar.width
|
||||
height = presenter.state.horizontalScrollbar.height
|
||||
|
||||
if measuringScrollbars
|
||||
height = 25
|
||||
@@ -19,6 +23,3 @@ ScrollbarCornerComponent = React.createClass
|
||||
div style:
|
||||
height: height + 1
|
||||
width: width + 1
|
||||
|
||||
shouldComponentUpdate: (newProps) ->
|
||||
not isEqualForProperties(newProps, @props, 'measuringScrollbars', 'visible', 'width', 'height')
|
||||
|
||||
@@ -53,17 +53,10 @@ TextEditorComponent = React.createClass
|
||||
if @performedInitialMeasurement
|
||||
visible = @isVisible()
|
||||
|
||||
{scrollHeight, scrollTop} = @presenter.state
|
||||
{scrollWidth, scrollLeft} = @presenter.state.content
|
||||
|
||||
horizontalScrollbarHeight = editor.getHorizontalScrollbarHeight()
|
||||
verticalScrollbarWidth = editor.getVerticalScrollbarWidth()
|
||||
verticallyScrollable = editor.verticallyScrollable()
|
||||
horizontallyScrollable = editor.horizontallyScrollable()
|
||||
hiddenInputStyle = @getHiddenInputPosition()
|
||||
hiddenInputStyle.WebkitTransform = 'translateZ(0)' if @useHardwareAcceleration
|
||||
|
||||
style.height = scrollHeight if @autoHeight
|
||||
style.height = @presenter.state.scrollHeight if @autoHeight
|
||||
|
||||
if useShadowDOM
|
||||
className = 'editor-contents--private'
|
||||
@@ -93,35 +86,23 @@ TextEditorComponent = React.createClass
|
||||
ref: 'horizontalScrollbar'
|
||||
className: 'horizontal-scrollbar'
|
||||
orientation: 'horizontal'
|
||||
presenter: @presenter
|
||||
onScroll: @onHorizontalScroll
|
||||
scrollLeft: scrollLeft
|
||||
scrollWidth: scrollWidth
|
||||
visible: horizontallyScrollable
|
||||
scrollableInOppositeDirection: verticallyScrollable
|
||||
verticalScrollbarWidth: verticalScrollbarWidth
|
||||
horizontalScrollbarHeight: horizontalScrollbarHeight
|
||||
useHardwareAcceleration: @useHardwareAcceleration
|
||||
|
||||
ScrollbarComponent
|
||||
ref: 'verticalScrollbar'
|
||||
className: 'vertical-scrollbar'
|
||||
orientation: 'vertical'
|
||||
presenter: @presenter
|
||||
onScroll: @onVerticalScroll
|
||||
scrollTop: scrollTop
|
||||
scrollHeight: scrollHeight
|
||||
visible: verticallyScrollable
|
||||
scrollableInOppositeDirection: horizontallyScrollable
|
||||
verticalScrollbarWidth: verticalScrollbarWidth
|
||||
horizontalScrollbarHeight: horizontalScrollbarHeight
|
||||
useHardwareAcceleration: @useHardwareAcceleration
|
||||
|
||||
# Also used to measure the height/width of scrollbars after the initial render
|
||||
ScrollbarCornerComponent
|
||||
ref: 'scrollbarCorner'
|
||||
visible: horizontallyScrollable and verticallyScrollable
|
||||
presenter: @presenter
|
||||
measuringScrollbars: @measuringScrollbars
|
||||
height: horizontalScrollbarHeight
|
||||
width: verticalScrollbarWidth
|
||||
|
||||
getInitialState: -> {}
|
||||
|
||||
@@ -780,7 +761,9 @@ TextEditorComponent = React.createClass
|
||||
height = (cornerNode.offsetHeight - cornerNode.clientHeight) or 15
|
||||
|
||||
editor.setVerticalScrollbarWidth(width)
|
||||
@presenter.setVerticalScrollbarWidth(width)
|
||||
editor.setHorizontalScrollbarHeight(height)
|
||||
@presenter.setHorizontalScrollbarHeight(height)
|
||||
|
||||
cornerNode.style.display = originalDisplayValue
|
||||
|
||||
|
||||
Reference in New Issue
Block a user