|
1 |
| -// @generated: @expo/[email protected] |
2 |
| -export { default } from '@expo/next-adapter/document'; |
| 1 | +import { Children } from "react"; |
| 2 | +import Document, { Html, Head, Main, NextScript } from "next/document"; |
| 3 | +import { AppRegistry } from "react-native-web"; |
| 4 | + |
| 5 | +// Follows the setup for react-native-web: |
| 6 | +// https://necolas.github.io/react-native-web/docs/setup/#root-element |
| 7 | +// Plus additional React Native scroll and text parity styles for various |
| 8 | +// browsers. |
| 9 | +// Force Next-generated DOM elements to fill their parent's height |
| 10 | +const style = ` |
| 11 | +html, body, #__next { |
| 12 | + -webkit-overflow-scrolling: touch; |
| 13 | +} |
| 14 | +#__next { |
| 15 | + display: flex; |
| 16 | + flex-direction: column; |
| 17 | + height: 100%; |
| 18 | +} |
| 19 | +html { |
| 20 | + scroll-behavior: smooth; |
| 21 | + -webkit-text-size-adjust: 100%; |
| 22 | +} |
| 23 | +body { |
| 24 | + /* Allows you to scroll below the viewport; default value is visible */ |
| 25 | + overflow-y: auto; |
| 26 | + overscroll-behavior-y: none; |
| 27 | + text-rendering: optimizeLegibility; |
| 28 | + -webkit-font-smoothing: antialiased; |
| 29 | + -moz-osx-font-smoothing: grayscale; |
| 30 | + -ms-overflow-style: scrollbar; |
| 31 | +} |
| 32 | +`; |
| 33 | + |
| 34 | +export default class MyDocument extends Document { |
| 35 | + static async getInitialProps({ renderPage }) { |
| 36 | + AppRegistry.registerComponent("main", () => Main); |
| 37 | + const { getStyleElement } = AppRegistry.getApplication("main"); |
| 38 | + const page = await renderPage(); |
| 39 | + const styles = [ |
| 40 | + <style |
| 41 | + key="react-native-style" |
| 42 | + dangerouslySetInnerHTML={{ __html: style }} |
| 43 | + />, |
| 44 | + getStyleElement(), |
| 45 | + ]; |
| 46 | + return { ...page, styles: Children.toArray(styles) }; |
| 47 | + } |
| 48 | + |
| 49 | + render() { |
| 50 | + return ( |
| 51 | + <Html style={{ height: "100%" }}> |
| 52 | + <Head /> |
| 53 | + <body style={{ height: "100%", overflow: "hidden" }}> |
| 54 | + <Main /> |
| 55 | + <NextScript /> |
| 56 | + </body> |
| 57 | + </Html> |
| 58 | + ); |
| 59 | + } |
| 60 | +} |
0 commit comments