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

feat(react) Support for JSX Widgets in React #9278

Open
wants to merge 27 commits into
base: master
Choose a base branch
from

Conversation

chrisgervang
Copy link
Collaborator

@chrisgervang chrisgervang commented Dec 5, 2024

For #9056

Background

Change List


// Iterate over views and reposition children associated with views
// TODO - Can we supply a similar function for the non-React case?
export default function positionChildrenUnderViews<ViewsT extends ViewOrViews>({
children,
deck,
ContextProvider
ContextProvider = DeckGlContext.Provider
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove the if (ContextProvider) { check on L97 if this is always defined now?

@felixpalmer felixpalmer mentioned this pull request Dec 6, 2024
36 tasks
Copy link
Collaborator

@felixpalmer felixpalmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, clean and not too much code :) I'm not that familiar with the React module so will leave the approval to @Pessimistress

modules/react/src/utils/use-widget.ts Show resolved Hide resolved
modules/react/src/index.ts Show resolved Hide resolved

this.props = {
...props,
transitionDuration: props.transitionDuration || 200,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if it would be nice to support defaultProps for widgets to avoid this sort of code

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Widget is only an interface, so I think the best we can do is lead by example of least annoying code to maintain. I just changed the dev guide to use this.id = props.id ?? this.id to avoid needing to repeat the hard-coded values, which is a marked improvement over this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be an abstract class instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's tempting but I'm more in favor of flexibility at this stage. I'm hesitant to abstract too early across widgets with there are so many ways to implement UI.

It's a bit of extra work to fill out the interface, but not much.

Maybe when we have a fuller library of examples exploring a breadth of use cases.. until then, there's nothing preventing an author from making their own abstract class.

modules/react/src/index.ts Show resolved Hide resolved
@@ -8,7 +8,7 @@ import type {Deck, Viewport, Widget, WidgetPlacement} from '@deck.gl/core';
import {render} from 'preact';
import {ButtonGroup, GroupedIconButton} from './components';

interface ZoomWidgetProps {
export interface ZoomWidgetProps {
Copy link
Collaborator Author

@chrisgervang chrisgervang Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pessimistress I'm noticing that the widget's onViewportChange isn't called on initialization. The user needs to interact with deck before a viewport is set.

Vanilla widgets work. Any idea what's different?

Copy link
Collaborator Author

@chrisgervang chrisgervang Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cause is this guard is hit before the viewports have been assigned to the widget. lastViewports was set on the first time props are set (when widgets: [] and it initialized the tooltip).
Screenshot 2024-12-12 at 5 18 07 PM

The goal of this code is to cache the current viewport so that the widget can use it as the starting point of its view modification.

The hook adds widgets in one-by-one: [] then [FirstWidget] then [FirstWidget, SecondWidget]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could push this check down into each widget to implement since the manager isn't aware of how widgets store viewports, or we could add viewports: {} to class Widget and have the manager check that instead? Thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See proposed fix in #9303

@chrisgervang chrisgervang changed the title [WIP] React Widgets feat(react) Support for JSX Widgets in React Dec 19, 2024
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.

3 participants