-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(swap): modals #2746
Merged
Merged
refactor(swap): modals #2746
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1de5b66
refactor(swap): modals
banklesss f3f6009
bottom tab alternate fix
banklesss 3f629f5
modal refactor
banklesss 268816b
bottom tab alternate fix
banklesss d068f83
bottom tab alternate fix
banklesss 0f27275
bottom tab alternate fix
banklesss 9f9a5cf
bottom tab alternate fix
banklesss fa219bb
Merge branch 'develop' into refactor/bottom-modals
banklesss 0b8dee5
Merge branch 'develop' into refactor/bottom-modals
michaeljscript d8551f7
android modal fix
banklesss 16e43ac
modal recolocation
banklesss e29c204
Merge remote-tracking branch 'origin/develop' into refactor/bottom-mo…
banklesss 517c9de
fix imports
banklesss 8d7796d
fix lint
banklesss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,66 @@ | ||
import {useNavigation} from '@react-navigation/native' | ||
import React from 'react' | ||
|
||
type ModalState = { | ||
height: number | ||
title: string | ||
content: React.ReactNode | ||
} | ||
type ModalActions = { | ||
openModal: (title: ModalState['title'], content: ModalState['content'], height?: ModalState['height']) => void | ||
closeModal: () => void | ||
} | ||
|
||
const ModalContext = React.createContext<undefined | (ModalState & ModalActions)>(undefined) | ||
|
||
export const useModal = () => { | ||
const value = React.useContext(ModalContext) | ||
if (!value) { | ||
throw new Error('useModal must be used within a ModalProvider') | ||
} | ||
return value | ||
} | ||
|
||
export const ModalProvider = ({ | ||
children, | ||
initialState, | ||
}: { | ||
children: React.ReactNode | ||
initialState?: Partial<ModalState> | ||
}) => { | ||
const [state, dispatch] = React.useReducer(modalReducer, {...defaultState, ...initialState}) | ||
const navigation = useNavigation() | ||
const actions = React.useRef<ModalActions>({ | ||
closeModal: () => { | ||
dispatch({type: 'close'}) | ||
navigation.goBack() | ||
}, | ||
openModal: (title: ModalState['title'], content: ModalState['content'], height?: ModalState['height']) => { | ||
dispatch({type: 'open', title, content, height}) | ||
navigation.navigate('modal') | ||
}, | ||
}).current | ||
|
||
const context = React.useMemo(() => ({...state, ...actions}), [state, actions]) | ||
|
||
return <ModalContext.Provider value={context}>{children}</ModalContext.Provider> | ||
} | ||
|
||
type ModalAction = | ||
| {type: 'open'; height: ModalState['height'] | undefined; content: ModalState['content']; title: ModalState['title']} | ||
| {type: 'close'} | ||
|
||
const modalReducer = (state: ModalState, action: ModalAction) => { | ||
switch (action.type) { | ||
case 'open': | ||
return {...state, content: action.content, height: action.height ?? defaultState.height, title: action.title} | ||
|
||
case 'close': | ||
return {...defaultState} | ||
|
||
default: | ||
throw new Error(`modalReducer invalid action`) | ||
} | ||
} | ||
|
||
const defaultState: ModalState = Object.freeze({content: undefined, height: 350, title: ''}) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternate fix for https://emurgo.atlassian.net/browse/YOMO-549