Add safe-area insets for notched devices (#222) - #257
Merged
Conversation
- Define --safe-area-inset-* CSS custom properties in :root using env(safe-area-inset-*) with 0px fallback - Apply safe-area padding to Navbar (top), Footer (bottom), Sidebar (top), and Modal (all four sides) layout components - Add useSafeAreaInsets hook for JS access to safe-area pixel values - Add <meta viewport-fit=cover> to index.html for iOS notch support - Write test coverage for the hook and CSS declarations - Document safe-area support in README
Contributor
|
Solid work, exactly what the issue asked for. ✨ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add safe-area inset support so content stays clear of notches, rounded corners, and the home indicator on devices like iPhone X+ and modern Android flagships.
Changes
CSS custom properties (
src/index.css)--safe-area-inset-top,--safe-area-inset-bottom,--safe-area-inset-left,--safe-area-inset-rightusingenv(safe-area-inset-*)with0pxfallback for non-notched browsers.Layout components
var(--safe-area-inset-top)to top padding so the navigation bar clears the notch.var(--safe-area-inset-bottom)to bottom padding so content avoids the home indicator.var(--safe-area-inset-top)to top padding for the sticky sidebar.index.htmlviewport-fit=coverto the<meta name="viewport">tag to allow the viewport to extend into the unsafe areas (prerequisite forenv(safe-area-inset-*)to return non-zero values).New hook:
useSafeAreaInsets(src/hooks/useSafeAreaInsets.js)getComputedStyleand returns{ top, bottom, left, right }in CSS pixels.resizeandorientationchangeevents so values update on device rotation.Testing
test/hooks/useSafeAreaInsets.test.js— 6 tests covering default state, pixel parsing, fractional values, and reactive updates on resize/orientationchange.test/safe-area.test.js— 8 tests verifying the CSS custom properties are declared inindex.cssand referenced by all four component CSS files.Documentation
README.md.Closes #222