-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1565 from TouK/NU-1881-fix-manual-window-size-change
Nu 1881 fix manual window size change
- Loading branch information
Showing
12 changed files
with
203 additions
and
171 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React, { createContext, PropsWithChildren, useCallback, useContext } from "react"; | ||
import { useTransitionMap } from "react-transition-state"; | ||
import { defaultFadeAnimation, FadeInAnimation } from "./getFadeInAnimation"; | ||
import { WindowId } from "../types"; | ||
|
||
const TRANSITION_TIMEOUT = 100; | ||
const transitionsAnimationTime = new Map<string, number>(); | ||
const TransitionContext = createContext<{ | ||
startTransition: (id: string) => Promise<boolean>; | ||
finishTransition: (id: string) => Promise<boolean>; | ||
getTransitionStyle: (id: string, fadeInAnimation?: FadeInAnimation) => string[]; | ||
}>(null); | ||
|
||
export const TransitionProvider = ({ children }: PropsWithChildren) => { | ||
const transition = useTransitionMap({ | ||
timeout: TRANSITION_TIMEOUT, | ||
exit: true, | ||
preExit: false, | ||
allowMultiple: true, | ||
}); | ||
|
||
const getTransitionStyle = useCallback( | ||
(id: WindowId, fadeInAnimation: FadeInAnimation = defaultFadeAnimation) => { | ||
transitionsAnimationTime.set(id, fadeInAnimation.animationTime * 1000); | ||
const transitionItem = transition.stateMap.get(id); | ||
const entered = transitionItem.status === "entered" && fadeInAnimation.entered; | ||
const exited = transitionItem.status === "exited" && fadeInAnimation.exited; | ||
|
||
return [fadeInAnimation.mounted, entered, exited]; | ||
}, | ||
[transition.stateMap], | ||
); | ||
|
||
const startTransition = useCallback( | ||
(id: WindowId) => { | ||
return new Promise<boolean>((resolve) => { | ||
transition.setItem(id); | ||
transition.toggle(id, true); | ||
const transitionAnimationTime = transitionsAnimationTime.get(id); | ||
|
||
setTimeout(() => { | ||
resolve(true); | ||
}, TRANSITION_TIMEOUT + transitionAnimationTime); | ||
}); | ||
}, | ||
[transition], | ||
); | ||
|
||
const finishTransition = useCallback( | ||
(id: WindowId) => { | ||
return new Promise<boolean>((resolve) => { | ||
transition.toggle(id, false); | ||
const transitionAnimationTime = transitionsAnimationTime.get(id); | ||
setTimeout(() => { | ||
transition.deleteItem(id); | ||
transitionsAnimationTime.delete(id); | ||
resolve(true); | ||
}, TRANSITION_TIMEOUT + transitionAnimationTime); | ||
}); | ||
}, | ||
[transition], | ||
); | ||
|
||
return ( | ||
<TransitionContext.Provider value={{ startTransition, finishTransition, getTransitionStyle }}>{children}</TransitionContext.Provider> | ||
); | ||
}; | ||
|
||
export const useTransition = () => { | ||
const context = useContext(TransitionContext); | ||
|
||
if (!context) { | ||
throw new Error(); | ||
} | ||
|
||
return context; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,19 @@ | ||
import { css } from "@emotion/css"; | ||
|
||
export const getFadeInAnimation = (t = 0.25) => ({ | ||
enter: css({ | ||
animationTime: t, | ||
mounted: css({ | ||
opacity: 0, | ||
}), | ||
enterActive: css({ | ||
opacity: 1, | ||
transition: `opacity ${t}s ease-in-out`, | ||
pointerEvents: "none", | ||
}), | ||
exit: css({ | ||
entered: css({ | ||
opacity: 1, | ||
}), | ||
exitActive: css({ | ||
exited: css({ | ||
opacity: 0, | ||
transition: `opacity ${t}s ease-in-out`, | ||
pointerEvents: "none", | ||
}), | ||
}); | ||
|
||
export type FadeInAnimation = ReturnType<typeof getFadeInAnimation>; | ||
export const defaultFadeAnimation = getFadeInAnimation(); | ||
export const fastFadeAnimation = getFadeInAnimation(0.15); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,32 @@ | ||
import { useTheme } from "@emotion/react"; | ||
import React, { useRef } from "react"; | ||
import { CSSTransition, TransitionGroup } from "react-transition-group"; | ||
import React from "react"; | ||
import { rgba } from "../../rgba"; | ||
import { fastFadeAnimation } from "../getFadeInAnimation"; | ||
import { Box } from "./useSnapAreas"; | ||
|
||
export const SnapMask = ({ previewBox }: { previewBox: Box }) => { | ||
const nodeRef = useRef<HTMLDivElement>(null); | ||
const { | ||
colors, | ||
spacing: { baseUnit }, | ||
} = useTheme(); | ||
|
||
return ( | ||
<TransitionGroup> | ||
<> | ||
{previewBox && ( | ||
<CSSTransition nodeRef={nodeRef} timeout={250} classNames={fastFadeAnimation}> | ||
<div | ||
ref={nodeRef} | ||
style={{ | ||
boxSizing: "border-box", | ||
position: "fixed", | ||
zIndex: 10, | ||
background: rgba(colors.focusColor, 0.25), | ||
border: `${Math.round(baseUnit / 3)}px solid ${colors?.focusColor}`, | ||
top: previewBox.y, | ||
left: previewBox.x, | ||
width: previewBox.width, | ||
height: previewBox.height, | ||
transition: "all .15s ease-in-out", | ||
}} | ||
/> | ||
</CSSTransition> | ||
<div | ||
style={{ | ||
boxSizing: "border-box", | ||
position: "fixed", | ||
zIndex: 10, | ||
background: rgba(colors.focusColor, 0.25), | ||
border: `${Math.round(baseUnit / 3)}px solid ${colors?.focusColor}`, | ||
top: previewBox.y, | ||
left: previewBox.x, | ||
width: previewBox.width, | ||
height: previewBox.height, | ||
transition: "all .15s ease-in-out", | ||
}} | ||
/> | ||
)} | ||
</TransitionGroup> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.