Merge pull request #2 from mlynch/main

Sync
This commit is contained in:
Leo Giovanetti
2020-12-29 18:54:01 -03:00
committed by GitHub
4 changed files with 34 additions and 27 deletions
+2
View File
@@ -1,5 +1,7 @@
# Next.js + Tailwind CSS + Capacitor for mobile app development
*Note: this repo is in active development and not quite ready for production use!*
This repo is a starting point for building an iOS, Android, and Progressive Web App with Tailwind CSS, Next.js, and Capacitor. It comes with some pre-built components that can be customized using Tailwind classes, and provides the most important UI controls needed to build native mobile experiences (tabs, nav bars, modals, menus, etc).
These components are baked into the starter and will be adopted into your project. This way you gain full control over the experience and can easily modify the look and feel of the components to match your design.
+13 -10
View File
@@ -8,22 +8,25 @@ const App = ({ children, className, ...props }) => {
const [darkMode, setDarkMode] = useState(false);
useEffect(async () => {
try {
let darkmodeConfig = await DarkMode.isDarkModeOn();
setDarkMode(darkmodeConfig.isDarkModeOn);
DarkMode.addListener("darkModeStateChanged", (state) => {
DarkMode.addListener('darkModeStateChanged', state => {
setDarkMode(state.isDarkModeOn);
});
} catch (e) {}
}, []);
return (<div {...props} className={classNames(
'flex h-screen flex-col',
className,
{
'dark': darkMode
}
)}>
return (
<div
{...props}
className={classNames('flex h-screen flex-col', className, {
dark: darkMode,
})}
>
{children}
</div>);
}
</div>
);
};
export default App;
+6 -4
View File
@@ -1,6 +1,6 @@
import { Plugins } from '@capacitor/core';
import classNames from 'classnames';
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import { useDrag } from 'react-use-gesture';
@@ -13,20 +13,22 @@ const Menu = ({ open, onClose, children, className, ...props }) => {
const [dragging, setDragging] = useState(false);
useEffect(async () => {
try {
let darkmodeConfig = await DarkMode.isDarkModeOn();
console.log({open, darkMode: darkmodeConfig.isDarkModeOn})
console.log({ open, darkMode: darkmodeConfig.isDarkModeOn });
Plugins.StatusBar.setStyle({
style: open && !darkmodeConfig.isDarkModeOn ? 'LIGHT' : 'DARK',
}).catch(() => {});
} catch (e) {}
}, [open]);
useLayoutEffect(() => {
useEffect(() => {
const rect = ref.current?.getBoundingClientRect();
setRect(rect);
setX(-rect.width);
}, []);
useLayoutEffect(() => {
useEffect(() => {
if (open) {
setX(0);
} else if (rect) {
+3 -3
View File
@@ -1,5 +1,5 @@
import classNames from 'classnames';
import { useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from 'react';
import { useCallback, useContext, useEffect, useRef, useState } from 'react';
import { useDrag } from 'react-use-gesture';
import Store from '../../store';
import { SafeAreaContext } from './SafeArea';
@@ -26,14 +26,14 @@ const Modal = ({ open, onClose, children }) => {
}, [safeAreaTop, rect]);
// Get the layout rectangle for the modal
useLayoutEffect(() => {
useEffect(() => {
const rect = ref.current?.getBoundingClientRect();
setRect(rect);
_close();
}, [safeAreaTop]);
// If open changes, open/close the modal
useLayoutEffect(() => {
useEffect(() => {
if (open) {
_open();
} else {