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

Feature Request: PIXI v8 support #476

Closed
guillaumebrunerie opened this issue Mar 8, 2024 · 7 comments
Closed

Feature Request: PIXI v8 support #476

guillaumebrunerie opened this issue Mar 8, 2024 · 7 comments
Labels
enhancement New feature or request v8 Issues related to Pixi React v8

Comments

@guillaumebrunerie
Copy link

guillaumebrunerie commented Mar 8, 2024

Description

Now that PIXI v8 has been released, it would be great to have support for it in pixi-react!

@cqh963852
Copy link

cqh963852 commented Mar 9, 2024

I just came to pixijs-react. I'm interested in supporting pixijs v8. I found that pixijs-react uses react-reconciler.

This is a bit complicated for me, can someone explain it?


I wrote a demo in react 18. I want to know if there are any potential problems with this way of writing?

utils.ts

export const useTimeoutEffect = (
  callback: () => Promise<void | (() => void)>,
  deps?: React.DependencyList
) => {
  useEffect(() => {
    let promise: Promise<void | (() => void)> | undefined;
    const handler = setTimeout(() => {
      promise = callback();
    });
    return () => {
      clearTimeout(handler);
      promise?.then((dispose) => {
        dispose?.();
      });
    };
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, deps);
};
import clsx from "clsx";
import { Application, Renderer } from "pixi.js";
import {
  createContext,
  CSSProperties,
  PropsWithChildren,
  useContext,
  useRef,
  useState,
} from "react";
import { useTimeoutEffect } from "../../utils";

interface IProps {
  className?: string;
  style?: CSSProperties;
}

const Context = createContext<Application<Renderer> | null>(null);

export const usePixiApp = () => {
  return useContext(Context);
};

const Scene = (props: PropsWithChildren<IProps>) => {
  let { className, style, children } = props;

  let stageContainer = useRef<HTMLDivElement>(null);
  const [pixiApp, setPixiApp] = useState<Application<Renderer> | null>(null);

  useTimeoutEffect(() => {
    const init = async () => {
      const app = new Application();
      if (stageContainer.current != null) {
        await app.init({
          resizeTo: stageContainer.current,
        });
        stageContainer.current.append(app.canvas);
        setPixiApp(app);

        return () => {
          stageContainer.current?.removeChild(app.canvas);
        };
      }
    };
    return init();
  }, []);

  return (
    <Context.Provider value={pixiApp}>
      <div
        ref={stageContainer}
        className={clsx(className, "grow overflow-hidden")}
        style={style}
      >
        {children}
      </div>
    </Context.Provider>
  );
};

export default Scene;

@guillaumebrunerie
Copy link
Author

@cqh963852 pixi-react is a custom renderer for React, making it possible to use PIXI inside a React app using regular JSX and without having to use refs and effects like you do.

There is nothing wrong with your code, it's just not pixi-react, for instance you won't be able to use JSX inside your scene.

@rnike
Copy link

rnike commented Mar 12, 2024

According to the message from Discord, it will be out asap

https://discord.com/channels/734147990985375826/968068526566965279/1214965701375299716

@Zyie
Copy link
Member

Zyie commented Mar 12, 2024

Hey everyone!

Yes i hope to have a v8 version out soon. Currently i am super busy with fixing up all the bugs from the main v8 release

@montoulieu
Copy link

Hey @Zyie, was wondering if there was any update on this?
Looking to use Pixi 8 with React for a client in the next few weeks. Thanks!

@CaptainStiggz
Copy link

Chiming in to say I'm also excited for this release. Working with gradients & SVGs, both of which appear to have first-class support in v8! Any idea on an ETA?

@Zyie

@trezy trezy mentioned this issue May 27, 2024
5 tasks
@trezy trezy added v8 Issues related to Pixi React v8 enhancement New feature or request labels Jun 15, 2024
@trezy
Copy link
Collaborator

trezy commented Jun 15, 2024

I'm closing this issue, as the future of this work will be tracked in #493. Please subscribe to that issue for further updates.

@trezy trezy closed this as completed Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request v8 Issues related to Pixi React v8
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants