Skip to content

Commit

Permalink
fix: use window height to determine controlbar height (#1620)
Browse files Browse the repository at this point in the history
This will hopefully fix the issue where the expanded control bar on the phone is too tall. Using window height should take into account the phone's available screen space considering address bar and navigation controls on some phone models.
  • Loading branch information
jenniferarnesen authored Mar 9, 2021
1 parent 66ac287 commit d7d730f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/components/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
--user-rows-height: calc(
var(--controlbar-padding) + (var(--user-rows-count) * var(--row-height))
);
--sm-expanded-controlbar-height: calc(
(var(--vh, 1vh) * 100) - var(--headerbar-height) - 32px
);

/* item variables */
--item-header-margin-top: 8px;
Expand Down
10 changes: 10 additions & 0 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ const App = props => {
props.fetchDashboards()
props.setControlBarRows()
props.setShowDescription()

// store the headerbar height for controlbar height calculations
const headerbarHeight = document
.querySelector('header')
.getBoundingClientRect().height

document.documentElement.style.setProperty(
'--headerbar-height',
`${headerbarHeight}px`
)
}, [])

useEffect(() => {
Expand Down
7 changes: 7 additions & 0 deletions src/components/ControlBar/ViewControlBar/DashboardsBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getRowsFromHeight } from './controlBarDimensions'
import { sGetControlBarUserRows } from '../../../reducers/controlBar'
import { acSetControlBarUserRows } from '../../../actions/controlBar'
import { apiPostControlBarRows } from '../../../api/controlBar'
import { useWindowDimensions } from '../../WindowDimensionsProvider'

import classes from './styles/DashboardsBar.module.css'

Expand All @@ -25,6 +26,7 @@ const DashboardsBar = ({
const [dragging, setDragging] = useState(false)
const userRowsChanged = useRef(false)
const ref = createRef()
const { height } = useWindowDimensions()

const rootElement = document.documentElement

Expand All @@ -44,6 +46,11 @@ const DashboardsBar = ({
rootElement.style.setProperty('--user-rows-count', userRows)
}, [userRows])

useEffect(() => {
const vh = height * 0.01
rootElement.style.setProperty('--vh', `${vh}px`)
}, [height])

useEffect(() => {
if (!dragging && userRowsChanged.current) {
apiPostControlBarRows(userRows)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
position: absolute;
display: flex;
flex-direction: column;
height: calc(100% - 32px);
height: var(--sm-expanded-controlbar-height);
}

.expanded .content {
Expand Down
1 change: 1 addition & 0 deletions src/components/__tests__/App.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ test('renders the app', () => {
}
const { container } = render(
<Provider store={mockStore(store)}>
<header style={{ height: '48px' }} />
<App />
</Provider>
)
Expand Down
3 changes: 3 additions & 0 deletions src/components/__tests__/__snapshots__/App.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

exports[`renders the app 1`] = `
<div>
<header
style="height: 48px;"
/>
<div
class="dashboard"
/>
Expand Down

0 comments on commit d7d730f

Please sign in to comment.