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

Issue in extending PaperRenderer #25

Closed
im-hamza-dev opened this issue Dec 29, 2021 · 3 comments
Closed

Issue in extending PaperRenderer #25

im-hamza-dev opened this issue Dec 29, 2021 · 3 comments
Assignees
Labels

Comments

@im-hamza-dev
Copy link

I am working to add raster feature in app, so looking for the extend feature but documentation is quite limited for me
Any idea what would be the structure of MyCustomStencilComponent here

My code:
image

Reference:
image

@psychobolt psychobolt self-assigned this Dec 29, 2021
@psychobolt
Copy link
Owner

psychobolt commented Dec 29, 2021

MyCustomStencilComponent is just alias for a constant string variable that you define in your renderer. For example, in the reference above I could use TYPE_NAME in the App component.

import MyCustomStencil from './MyCustomStencil';

const TYPE_NAME = 'myStencil';

class MyPaperRenderer extends PaperRenderer {
  getInstanceFactory() {
    return { 
      ...this.defaultTypes, /* 
        refer to default types
        see https://github.com/psychobolt/react-paperjs/blob/master/src/Paper.types.js#L42 
      */
      [TYPE_NAME]: (props, paper) => new MyCustomStencil(props),
    };
  }
}

const App = (props) => (
   <PaperContainer renderer={MyPaperRenderer}>
     <TYPE_NAME />
   </PaperContainer>
);

You can look at the reference, and see there is a link to default types.

Below is additional info, not pertaining to your original question but helpful to the docs.

There is no specific structure for the class MyCustomStencil, but its expected you composite it so it extends Paper's prototypes such as from Item or Group. Then the raster is instantiated and have proper methods to append to the tree for during react-paperjs' reconciler's lifecycle. (see host config). However, if you need further advanced customization, lucky enough you already have access to extend the renderer's host config.

@im-hamza-dev
Copy link
Author

Oh, Thanks a lot @psychobolt , I was close and now issue resolved
Successfully extended.

@psychobolt
Copy link
Owner

psychobolt commented Dec 29, 2021

@im-hamza-dev No problem, I just merged a related PR. There is a new version (1.0.3) out now with these changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants