-
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.
The second release(custom labels) (#9)
* Feat/custom labels (#8) * feat(notes): handle displaying the separator correctly * feat(notes): implement scroll to top on logo press * feat: implement the type selector modal * feat(labels): integrate with labels endpoints, implement the logic * fix(label): handle displaying input over the keyboard * refactor(notes): structure files by folders * feat(labels): implement the categories selector * chore: add a build command
- Loading branch information
1 parent
1ad6bf3
commit 3688b8b
Showing
38 changed files
with
1,769 additions
and
506 deletions.
There are no files selected for viewing
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
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,149 @@ | ||
import React, { | ||
PropsWithChildren, | ||
useCallback, | ||
useEffect, | ||
useMemo, | ||
useRef, | ||
} from "react"; | ||
import { Animated, Modal, useWindowDimensions } from "react-native"; | ||
import style from "styled-components"; | ||
|
||
import styled from "styled-components/native"; | ||
|
||
type Props = { | ||
isVisible: boolean; | ||
modalAnimationTime?: number; | ||
statusBarTranslucent?: boolean; | ||
bgOpacity: number; | ||
closeTriggered?: boolean; | ||
setIsVisible: (arg: boolean) => void; | ||
setCloseTriggered?: (value: boolean) => void; | ||
onClose?: () => void; | ||
}; | ||
|
||
const AnimatedModalContainer = ({ | ||
modalAnimationTime, | ||
isVisible, | ||
bgOpacity, | ||
closeTriggered, | ||
children, | ||
setIsVisible, | ||
setCloseTriggered, | ||
onClose, | ||
}: PropsWithChildren<Props>): JSX.Element => { | ||
const { height: screenHeight } = useWindowDimensions(); | ||
|
||
const modalTransition = useRef(new Animated.Value(0)).current; | ||
|
||
const modalContainerStyle = useMemo( | ||
() => ({ | ||
transform: [ | ||
{ | ||
translateY: modalTransition.interpolate({ | ||
outputRange: [screenHeight, 0], | ||
inputRange: [0, 1], | ||
}), | ||
}, | ||
], | ||
}), | ||
[modalTransition, screenHeight], | ||
); | ||
|
||
const modalTransitionDownAnimation = useMemo( | ||
() => | ||
Animated.timing(modalTransition, { | ||
duration: modalAnimationTime, | ||
useNativeDriver: true, | ||
toValue: 0, | ||
}), | ||
[modalTransition, modalAnimationTime], | ||
); | ||
|
||
const modalTransitionUpAnimation = useMemo( | ||
() => | ||
Animated.timing(modalTransition, { | ||
duration: modalAnimationTime, | ||
useNativeDriver: true, | ||
toValue: 1, | ||
}), | ||
[modalAnimationTime, modalTransition], | ||
); | ||
|
||
// Close modal animation | ||
const closeModal = useCallback(() => { | ||
modalTransitionDownAnimation.start(({ finished }) => { | ||
if (finished) { | ||
setIsVisible(false); | ||
|
||
onClose?.(); | ||
} | ||
}); | ||
}, [modalTransitionDownAnimation, setIsVisible, onClose]); | ||
|
||
const onRequestClose = useCallback(() => { | ||
setIsVisible(false); | ||
}, [setIsVisible]); | ||
|
||
// Modal background Animation | ||
useEffect(() => { | ||
requestAnimationFrame(() => { | ||
isVisible && modalTransitionUpAnimation.start(); | ||
}); | ||
|
||
return () => { | ||
modalTransitionUpAnimation.stop(); | ||
}; | ||
}, [isVisible, modalTransitionUpAnimation]); | ||
|
||
// closing modal outside the component | ||
useEffect(() => { | ||
if (closeTriggered && setCloseTriggered) { | ||
closeModal(); | ||
setCloseTriggered(false); | ||
} | ||
}, [closeModal, closeTriggered, setCloseTriggered]); | ||
|
||
return ( | ||
<Modal | ||
onRequestClose={onRequestClose} | ||
presentationStyle="overFullScreen" | ||
statusBarTranslucent | ||
animationType="fade" | ||
visible={isVisible} | ||
transparent | ||
> | ||
<SBackground bgOpacity={bgOpacity} /> | ||
|
||
<SModalContainer style={modalContainerStyle}> | ||
<STopSpace onTouchEnd={closeModal} /> | ||
|
||
{children} | ||
</SModalContainer> | ||
</Modal> | ||
); | ||
}; | ||
|
||
const SModalContainer = style(Animated.View)` | ||
height: 100%; | ||
width: 100%; | ||
justify-content: flex-end; | ||
`; | ||
|
||
const SBackground = styled.View<{ bgOpacity: number }>` | ||
position: absolute; | ||
top: 0; | ||
bottom: -100px; | ||
z-index: -100; | ||
flex: 1; | ||
width: 100%; | ||
background-color: ${({ theme }) => theme.colors.black}; | ||
opacity: ${({ bgOpacity }) => bgOpacity}; | ||
`; | ||
|
||
const STopSpace = styled.View` | ||
flex: 1; | ||
width: 100%; | ||
background-color: transparent; | ||
`; | ||
|
||
export default AnimatedModalContainer; |
Oops, something went wrong.