Skip to content

Commit

Permalink
improve setup for react-native-web with next.js
Browse files Browse the repository at this point in the history
  • Loading branch information
LunatiqueCoder committed Dec 19, 2022
1 parent 17bccd1 commit e350f1a
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions template/src/pages/_document.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {Children} from 'react';
import Document, {Html, Head, Main, NextScript} from 'next/document';
import {AppRegistry} from 'react-native';
import config from '../app.json';
// Force Next-generated DOM elements to fill their parent's height
const normalizeNextElements = `
#__next {
display: flex;
flex-direction: column;
height: 100%;
}
`;

export default class MyDocument extends Document {
static async getInitialProps({renderPage}) {
AppRegistry.registerComponent(config.name, () => Main);
const {getStyleElement} = AppRegistry.getApplication(config.name);
const page = await renderPage();
const styles = [
<style dangerouslySetInnerHTML={{__html: normalizeNextElements}} />,
getStyleElement(),
];
return {...page, styles: Children.toArray(styles)};
}

render() {
return (
<Html style={{height: '100%'}}>
<Head />
<body style={{height: '100%', overflow: 'hidden'}}>
<Main />
<NextScript />
</body>
</Html>
);
}
}

1 comment on commit e350f1a

@vercel
Copy link

@vercel vercel bot commented on e350f1a Dec 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

luna – ./

luna-gamma.vercel.app
luna-git-nextjs-criszz77.vercel.app
luna-criszz77.vercel.app

Please sign in to comment.