Code Monkey home page Code Monkey logo

Comments (13)

patrickhpan avatar patrickhpan commented on May 18, 2024 1

The difference to me is that in React it only really makes sense to have one "App" running at any time whereas in Sketch it's highly useful to have multiple "App"s on the same Page to represent different states.

What about a nonstandard render() method that takes an optional third parameter, append, that defaults to true but if false calls

page.addLayers([layer]);

instead of

page.replaceAllLayersWithLayers([layer]);

Thus, you could use

render(<FirstThing />, page)
render(<AlsoOnSamePage />, page, false

to force rendering on the same page?


And rendering one component per page can be done using by calling context.document.removePage(context.currentPage()) enough times to remove all pages, and appending new blank pages into an array, and then rendering one component per page. This hack is here

from react-sketchapp.

kristinbaumann avatar kristinbaumann commented on May 18, 2024 1

@patrickhpan provided a gist to generate multiple artboards within one artboard here: https://gist.github.com/patrickhpan/a47ee004b5c77854be4cbfd29c09be17.
Works quite well for me.

from react-sketchapp.

IlyasM avatar IlyasM commented on May 18, 2024

That would be really useful

from react-sketchapp.

patrickhpan avatar patrickhpan commented on May 18, 2024

Interestingly, the exact same code segment above results in only the last render() workingβ€”it looks like each render() replaces the page's existing contents. Is anyone else encountering this? I'm on the latest Sketch (43.2)

I came up with a hack by nesting Artboards within a root Artboard, which seems to work okay. It's here.

from react-sketchapp.

jeroenransijn avatar jeroenransijn commented on May 18, 2024

Super awesome project. This one is key in adoption for me.

from react-sketchapp.

mathieudutour avatar mathieudutour commented on May 18, 2024

yes, that was the old behaviour which didn't replace the content but append to it. Looks like this should have a higher priority now

from react-sketchapp.

jemgold avatar jemgold commented on May 18, 2024

Sorry, I totally forgot that we changed how render works recently πŸ™ƒ - please disregard my initial message.

Previously we appended to the document rather than replacing. This let you hack multiple artboards by rendering twice etc, with the side effect of having to manually clear a document or ending up with tons of duplicate content.

For everything, consider how React would work.
Calling

render(<Thing />, document.getElementById('root'));
render(<Thing />, document.getElementById('root'));

would rerender Thing into root, but you'd only see it once. to see two things, you'd provide a different container

render(<Thing />, document.getElementById('foo'));
render(<Thing />, document.getElementById('bar'));

you don't have to use context.document.currentPage() - consider it ~= rendering directly in to <body>.

equally if you held a reference to a selection or to a group you could render into that - there aren't examples yet because it's kinda fiddly but that's basically the metaphor.

you can also render Artboards inside of Artboards but it's pretty broken, and Sketch won't let you do that by hand so it's going to be glitchy.

I agree with y'all that this is a high priority for me too - hope you can bear with us whilst we find the perfect solution (and let's discuss possible APIs for it here β€” what would a component that's higher-level than an Artboard be called?)

from react-sketchapp.

jemgold avatar jemgold commented on May 18, 2024
  1. a separate ~= renderAndAppend method. would avoid cluttering the function signature
  2. a method that instantiates the object but doesn't insert it at all - just returns it for you to do with as you wish.
const layer = renderToObjOrSomething(<Foo /));
context.document.currentPage().addLayers([ layer ]);
  1. a higher level component like <Page> or <Canvas> or something that can contain multiple artboards and lays them out with flexbox etc
  2. some helpers to simplify the render(<Foo />, ANY_TARGET_OTHER_THAN_CURRENT_PAGE) workflow - you have to know some CocoaScript to get it to work, so maybe a simple getLayerByName('foo') helper would be good to include.

We want to support rerendering as the primary method β€” it enables livereloading, which was previously tricky, and I think a combination of the above methods will work (because they target slightly different usecases)

from react-sketchapp.

masato-io avatar masato-io commented on May 18, 2024

+1. This one is the key for adoption for me as well.

from react-sketchapp.

houhr avatar houhr commented on May 18, 2024

+1. This feature is so necessary to compose a page like the Symbols page in Sketch.

from react-sketchapp.

ljharb avatar ljharb commented on May 18, 2024

(general PSA: please use reaction emojis on the original post to indicate support on GitHub rather than posting comments on issue threads)

from react-sketchapp.

fresh5447 avatar fresh5447 commented on May 18, 2024

The hack does work but I don't love it. I thought the point of this project was design scalability? If my current understanding is correct, I can easily swap out which component is being rendered which is fine for development. However, do I now have to save every different (view) Artboard as a different directory/file? Then at the end of the day open up all the single projects and drag and drop to combine them into a single, useful, directory to show a client or the team? This seems too odd to be true, I am really hoping I am misunderstanding the functionality.

from react-sketchapp.

anymost avatar anymost commented on May 18, 2024

So, how to append an Artboard to page while reserve old Artboards in the same page?

from react-sketchapp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.