2023-01-10 11:25:26 +00:00
|
|
|
import NextDocument, { Head, Html, Main, NextScript } from 'next/document'
|
|
|
|
import { Children } from 'react'
|
2023-01-16 12:08:24 +00:00
|
|
|
import { AppRegistry } from 'react-native'
|
2023-01-10 11:25:26 +00:00
|
|
|
|
|
|
|
import Tamagui from '../tamagui.config'
|
|
|
|
|
2023-01-16 12:08:24 +00:00
|
|
|
// TODO: the recommended approach breaks HMR when Tmaagui.getCSS() is called in the getInitialProps method.
|
2023-01-10 11:25:26 +00:00
|
|
|
export default class Document extends NextDocument {
|
2023-01-16 12:08:24 +00:00
|
|
|
// static async getInitialProps({ renderPage }: any) {
|
|
|
|
// AppRegistry.registerComponent('Main', () => Main)
|
|
|
|
// const page = await renderPage()
|
|
|
|
|
|
|
|
// // @ts-ignore
|
|
|
|
// const { getStyleElement } = AppRegistry.getApplication('Main')
|
|
|
|
|
|
|
|
// /**
|
|
|
|
// * Note: be sure to keep tamagui styles after react-native-web styles like it is here!
|
|
|
|
// * So Tamagui styles can override the react-native-web styles.
|
|
|
|
// */
|
|
|
|
// const styles = [
|
|
|
|
// getStyleElement(),
|
|
|
|
// <style
|
|
|
|
// key="tamagui-css"
|
|
|
|
// dangerouslySetInnerHTML={{ __html: Tamagui.getCSS() }}
|
|
|
|
// />,
|
|
|
|
// ]
|
2023-01-10 11:25:26 +00:00
|
|
|
|
2023-01-16 12:08:24 +00:00
|
|
|
// return { ...page, styles: Children.toArray(styles) }
|
|
|
|
// }
|
|
|
|
|
|
|
|
static async getInitialProps({ renderPage }) {
|
|
|
|
AppRegistry.registerComponent('app', () => Main)
|
2023-01-10 11:25:26 +00:00
|
|
|
// @ts-ignore
|
2023-01-16 12:08:24 +00:00
|
|
|
const { getStyleElement } = AppRegistry.getApplication('app')
|
|
|
|
|
|
|
|
const page = await renderPage()
|
2023-01-10 11:25:26 +00:00
|
|
|
|
|
|
|
const styles = [
|
2023-01-16 12:08:24 +00:00
|
|
|
// <style dangerouslySetInnerHTML={{ __html: normalizeNextElements }} />,
|
|
|
|
getStyleElement(),
|
|
|
|
// <style
|
|
|
|
// key="tamagui-css"
|
|
|
|
// dangerouslySetInnerHTML={{ __html: Tamagui.getCSS() }}
|
|
|
|
// />,
|
2023-01-10 11:25:26 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
return { ...page, styles: Children.toArray(styles) }
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2023-01-16 12:08:24 +00:00
|
|
|
<Html lang="en">
|
2023-01-10 11:25:26 +00:00
|
|
|
<Head>
|
|
|
|
<meta httpEquiv="X-UA-Compatible" content="IE=edge" />
|
2023-01-16 12:08:24 +00:00
|
|
|
<style
|
|
|
|
id="stitches"
|
|
|
|
dangerouslySetInnerHTML={{ __html: Tamagui.getCSS() }}
|
|
|
|
/>
|
2023-01-10 11:25:26 +00:00
|
|
|
</Head>
|
|
|
|
<body>
|
|
|
|
<Main />
|
|
|
|
<NextScript />
|
|
|
|
</body>
|
|
|
|
</Html>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|