Skip to content
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

Merged
merged 3 commits into from
Jan 11, 2024
Merged

App Tabs and Search #4631

merged 3 commits into from
Jan 11, 2024

Conversation

samholmes
Copy link
Contributor

@samholmes samholmes commented Dec 15, 2023

CHANGELOG

Does this branch warrant an entry to the CHANGELOG?

  • Yes
  • No

Dependencies

#4683

Requirements

If you have made any visual changes to the GUI. Make sure you have:

  • Tested on iOS device
  • Tested on Android device
  • Tested on small-screen device (iPod Touch)
  • Tested on large-screen device (tablet)

Copy link
Contributor

@swansontec swansontec left a 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>] {
Copy link
Contributor

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.

src/state/index.ts Outdated Show resolved Hide resolved
src/state/StateProvider.tsx Outdated Show resolved Hide resolved
src/state/SceneDrawerState.tsx Outdated Show resolved Hide resolved
src/state/SceneScrollState.tsx Outdated Show resolved Hide resolved
src/state/StateProvider.tsx Outdated Show resolved Hide resolved
src/state/SceneDrawerState.tsx Outdated Show resolved Hide resolved
@samholmes samholmes force-pushed the sam/app-tabs branch 2 times, most recently from 0083296 to edd83af Compare January 5, 2024 07:58
@samholmes samholmes mentioned this pull request Jan 5, 2024
6 tasks
Copy link
Contributor

@swansontec swansontec left a 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!

Comment on lines 9 to 13
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 }) {
Copy link
Contributor

@swansontec swansontec Jan 9, 2024

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.

@samholmes samholmes merged commit de45a2f into develop Jan 11, 2024
2 checks passed
@samholmes samholmes deleted the sam/app-tabs branch January 11, 2024 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants