-
Notifications
You must be signed in to change notification settings - Fork 258
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
App Tabs and Search #4631
App Tabs and Search #4631
Conversation
b0c36f4
to
6265290
Compare
6265290
to
b9c21ab
Compare
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.
The state provider system needs a little clean-up, but the animation stuff seems OK. I would need a sidebar to understand it a little better, but I don't see any red flags aside from the window dimensions issue.
@@ -0,0 +1,11 @@ | |||
import React from 'react' | |||
|
|||
export function withContextProvider<T>(getValue: () => T): [React.FunctionComponent<{ children: React.ReactNode }>, React.Context<T | undefined>] { |
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.
This isn't really a HOC, since it takes a callback function, not a component. It needs another name and another home.
I am also worried about updating the context value on every render - I think this will force a re-render of each linked child. According to the docs, React uses ===
on the context value to decide whether or not an update has occurred. Using a raw return {...}
will never be ===
equal, so the update will always take place.
So, if we want to implement these contexts correctly, we need to do something like this:
export const SceneDrawerContext = React.createContext(undefined)
export function SceneDrawerProvider(props: { children: React.ReactNode }) {
const [isRatioDisabled, setIsRatioDisabled] = React.useState(false)
const drawerHeight = useSharedValue(0)
const drawerOpenRatio = useSharedValue(1)
const drawerOpenRatioStart = useSharedValue(1)
const value = React.useMemo(
() => ({
drawerHeight,
drawerOpenRatio,
drawerOpenRatioStart,
isRatioDisabled,
setIsRatioDisabled
}),
[drawerHeight, drawerOpenRatio, drawerOpenRatioStart, isRatioDisabled]
)
return <SceneDrawerContext.Provider value={value}>{props.children}</SceneDrawerContext.Provider>
}
I'm not sure if your withContextProvider
helper function adds much, compared to just doing things directly as above. Maybe you can refactor your helper to somehow help with the memorization, but I don't have a clear idea about what this would look like.
Another idea is to combine makeUseContextValue
and withContextProvider
into a single step - createStateProvider
. This would reflect the StateProvier
nomenclature used later, and will create both the hook and the provider in one step.
0083296
to
edd83af
Compare
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.
Yeah, the state provider stuff looks really nice now!
src/state/createStateProvider.tsx
Outdated
export function createStateProvider<Value>(hookFn: () => Value): [React.FunctionComponent<{ children: React.ReactNode }>, () => Value] { | ||
const Context = React.createContext<Value | undefined>(undefined) | ||
function WithContext({ children }: { children: React.ReactNode }) { |
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.
Optional: You could put interface Props { children: React.ReactNode }
at the top, and then you could do React.FunctionComponent<Props>
and ({children}: Props)
instead of duplicating the props type.
edd83af
to
85e71ca
Compare
85e71ca
to
101bb16
Compare
101bb16
to
ba16632
Compare
CHANGELOG
Does this branch warrant an entry to the CHANGELOG?
Dependencies
#4683
Requirements
If you have made any visual changes to the GUI. Make sure you have: