немного перпеписана логика перехода в адаптивный режим, теперь осуществляется проверка на ориентацию утройства
This commit is contained in:
+12
-6
@@ -1,11 +1,12 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import './App.css';
|
import './App.css';
|
||||||
import { ContextWindowHeight } from './components/contextWindowHeight';
|
import { ContextWindowHeightOrientation } from './components/contextWindowHeight';
|
||||||
import { MainScreen } from './components/mainScreen/mainScreen';
|
import { MainScreen } from './components/mainScreen/mainScreen';
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
// const [windowHeight, setWindowHeight] = useState<number>(window.screen.availHeight); - не робит на iphone
|
// const [windowHeight, setWindowHeight] = useState<number>(window.screen.availHeight); - не робит на iphone
|
||||||
const [windowHeight, setWindowHeight] = useState<number>(window.visualViewport.height);
|
const [windowHeight, setWindowHeight] = useState<number>(window.visualViewport.height);
|
||||||
|
const [isLandscape, setIsLandscape] = useState<boolean>(window.orientation !== 0);
|
||||||
const [currentOrientaton, setCurrentOrientaton] = useState<number>(window.orientation);
|
const [currentOrientaton, setCurrentOrientaton] = useState<number>(window.orientation);
|
||||||
|
|
||||||
|
|
||||||
@@ -14,13 +15,18 @@ function App() {
|
|||||||
setWindowHeight(e.currentTarget.height);
|
setWindowHeight(e.currentTarget.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
// !!! работает на свойстве помеченном как deprecate - на айфоне иначе хз как
|
// !!! работает на свойстве помеченном как deprecated - на айфоне иначе хз как
|
||||||
window.onorientationchange = e => {
|
window.onorientationchange = e => {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
let angle = e.target.orientation;
|
let angle = e.target.orientation;
|
||||||
if(currentOrientaton !== angle) {
|
if(currentOrientaton !== angle) {
|
||||||
setCurrentOrientaton(angle);
|
setCurrentOrientaton(angle);
|
||||||
}
|
}
|
||||||
|
if(angle !== 0) {
|
||||||
|
setIsLandscape(true);
|
||||||
|
} else {
|
||||||
|
setIsLandscape(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -36,9 +42,9 @@ function App() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
<ContextWindowHeight.Provider value={windowHeight}>
|
<ContextWindowHeightOrientation.Provider value={{windowHeight: windowHeight, isLandscape: isLandscape}}>
|
||||||
<MainScreen />
|
<MainScreen />
|
||||||
</ContextWindowHeight.Provider>
|
</ContextWindowHeightOrientation.Provider>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
export const ContextWindowHeight = React.createContext(window.screen.availHeight);
|
export const ContextWindowHeightOrientation = React.createContext({
|
||||||
|
windowHeight: window.screen.availHeight,
|
||||||
|
isLandscape: window.orientation !== 0
|
||||||
|
});
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useContext, useEffect, useState } from "react";
|
import React, { useContext, useEffect, useState } from "react";
|
||||||
import { CSSTransition } from "react-transition-group";
|
import { CSSTransition } from "react-transition-group";
|
||||||
import { ContextWindowHeight } from "../contextWindowHeight";
|
import { ContextWindowHeightOrientation } from "../contextWindowHeight";
|
||||||
import './mainScreen.css';
|
import './mainScreen.css';
|
||||||
import { MobileAddPart } from "./mobileAddPart/mobileAddPart";
|
import { MobileAddPart } from "./mobileAddPart/mobileAddPart";
|
||||||
import { PushMessage } from "./pushMessage/pushMessage";
|
import { PushMessage } from "./pushMessage/pushMessage";
|
||||||
@@ -21,7 +21,7 @@ export const MainScreen:React.FC = React.memo(() => {
|
|||||||
setShowMobileLangSelectorPart,
|
setShowMobileLangSelectorPart,
|
||||||
setShowMobileSharePart
|
setShowMobileSharePart
|
||||||
]
|
]
|
||||||
const windowHeight = useContext(ContextWindowHeight);
|
const {windowHeight, isLandscape} = useContext(ContextWindowHeightOrientation);
|
||||||
|
|
||||||
function onClickToolbar() {
|
function onClickToolbar() {
|
||||||
setShowToolbar(!showToolbar);
|
setShowToolbar(!showToolbar);
|
||||||
@@ -139,7 +139,7 @@ export const MainScreen:React.FC = React.memo(() => {
|
|||||||
/>
|
/>
|
||||||
</CSSTransition>
|
</CSSTransition>
|
||||||
{
|
{
|
||||||
windowHeight < 700?
|
windowHeight < 700 && isLandscape?
|
||||||
<>
|
<>
|
||||||
<CSSTransition
|
<CSSTransition
|
||||||
in={showMobileUsersPart}
|
in={showMobileUsersPart}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useContext, useState } from "react";
|
import React, { useContext, useState } from "react";
|
||||||
import { CSSTransition } from "react-transition-group";
|
import { CSSTransition } from "react-transition-group";
|
||||||
import { ContextWindowHeight } from "../../contextWindowHeight";
|
import { ContextWindowHeightOrientation } from "../../contextWindowHeight";
|
||||||
import { ControlButton } from "./controlButton";
|
import { ControlButton } from "./controlButton";
|
||||||
import { ToolbarButton } from "./toolbarButton";
|
import { ToolbarButton } from "./toolbarButton";
|
||||||
import { BorderLine } from "./toolbarButtonContainerBorderLine";
|
import { BorderLine } from "./toolbarButtonContainerBorderLine";
|
||||||
@@ -24,7 +24,7 @@ type TProps = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const ButtonContainer:React.FC<TProps> = React.memo((props) => {
|
export const ButtonContainer:React.FC<TProps> = React.memo((props) => {
|
||||||
const windowHeight = useContext(ContextWindowHeight);
|
const {windowHeight, isLandscape} = useContext(ContextWindowHeightOrientation);
|
||||||
// const [openedAddButtons, setOpenedAddButtons] = useState<string>('');
|
// const [openedAddButtons, setOpenedAddButtons] = useState<string>('');
|
||||||
const controlStates = ['default', 'questing', 'return', 'questing'];// temp
|
const controlStates = ['default', 'questing', 'return', 'questing'];// temp
|
||||||
const [currentControlState, setCurrentControlState] = useState<number>(0); // temp
|
const [currentControlState, setCurrentControlState] = useState<number>(0); // temp
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useContext, useState } from "react";
|
import React, { useContext, useState } from "react";
|
||||||
import { ContextWindowHeight } from "../../contextWindowHeight";
|
import { ContextWindowHeightOrientation } from "../../contextWindowHeight";
|
||||||
import { ButtonContainer } from "./buttonContainer";
|
import { ButtonContainer } from "./buttonContainer";
|
||||||
import { ToolbarButton } from "./toolbarButton";
|
import { ToolbarButton } from "./toolbarButton";
|
||||||
import { CaptionToolbarButtons } from "./typeCaptionButtons";
|
import { CaptionToolbarButtons } from "./typeCaptionButtons";
|
||||||
@@ -17,7 +17,7 @@ type TProps = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const Toolbar:React.FC<TProps> = React.memo((props) => {
|
export const Toolbar:React.FC<TProps> = React.memo((props) => {
|
||||||
const windowHeight = useContext(ContextWindowHeight);
|
const {windowHeight, isLandscape} = useContext(ContextWindowHeightOrientation);
|
||||||
const [showAddButtonsContOnDekstop, setShowAddButtonsContOnDekstop] = useState<boolean>(false);
|
const [showAddButtonsContOnDekstop, setShowAddButtonsContOnDekstop] = useState<boolean>(false);
|
||||||
const [openedAddButtons, setOpenedAddButtons] = useState<string>('');
|
const [openedAddButtons, setOpenedAddButtons] = useState<string>('');
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ export const Toolbar:React.FC<TProps> = React.memo((props) => {
|
|||||||
setShowAddButtonsContOnDekstop(!showAddButtonsContOnDekstop);
|
setShowAddButtonsContOnDekstop(!showAddButtonsContOnDekstop);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(windowHeight < 700) {
|
if(windowHeight < 700 && isLandscape) {
|
||||||
return <div className={`toolbar-container ${props.isOpen ? 'opened' : 'closed'}`}>
|
return <div className={`toolbar-container ${props.isOpen ? 'opened' : 'closed'}`}>
|
||||||
<div className="toolbar-field">
|
<div className="toolbar-field">
|
||||||
<div className="toolbar-field-part">
|
<div className="toolbar-field-part">
|
||||||
|
|||||||
Reference in New Issue
Block a user