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

Hooks! #446

Closed
2 tasks done
btzr-io opened this issue Apr 26, 2020 · 7 comments
Closed
2 tasks done

Hooks! #446

btzr-io opened this issue Apr 26, 2020 · 7 comments

Comments

@btzr-io
Copy link
Owner

btzr-io commented Apr 26, 2020

Hooks will make the api more transparent and easy to access, there will be no need to provide a UI and devs will have free access to build controls and extensions without limitations of the current structure.

Here are some initial tasks:

  • Expose the context provider of the component
  • Expose methods as hooks ( useNavigateToPage, useGetZoomLevels, etc... )
@btzr-io
Copy link
Owner Author

btzr-io commented Apr 26, 2020

@btzr-io btzr-io pinned this issue Apr 26, 2020
@btzr-io
Copy link
Owner Author

btzr-io commented Apr 26, 2020

react-router provides a similar api, so we should expose the main component ( Under the hood is just a wrapper for the context provider ) like this:

<Villain>{ Indside here any component can use our custom hooks }</Villain>

This is how we can expose the methods as hooks:

export function useCurrentPage() {
  // We can access directly to our context:
  return useContext(Context).currentPage;
}

Example usage:

  const currentPage = useCurrentPage();
  const navigateForward = useNavigateForward();
  ...
 <Villain>
  <div> Current page: {currentPage}</div>
  <button onClick={navigateForward}> Next page </button>
 </Villain>

https://github.com/ReactTraining/react-router/blob/master/packages/react-router/modules/hooks.js
https://github.com/ReactTraining/react-router/blob/master/packages/react-router/modules/Router.js

This was referenced Apr 26, 2020
@btzr-io
Copy link
Owner Author

btzr-io commented Apr 26, 2020

I'll start to do some work on this branch, please let me know if you want to help ✌️
https://github.com/btzr-io/Villain/tree/hooks

@btzr-io btzr-io added this to the v2.0.0 milestone Sep 3, 2020
@btzr-io btzr-io mentioned this issue Sep 3, 2020
16 tasks
@btzr-io
Copy link
Owner Author

btzr-io commented Sep 3, 2020

First draft of Navigation hook:

const navigation = useNavigation();
// ...
{
  // Total count of pages
  totalPages: 24,
  // Can navigate to previous page
  canBack: false,
  // Can navigate to next page
  canForward: true,
  // Current page index ( 0 = first index )
  currentPage: 0,
 // Current page number ( 1 = first page / cover )
  currentPageNumber: 1,
  // Actions:
  // Go to page from index
  go(index),
  // Go to previous page
  back(),
  // Go to next page
  forward(),
}

@btzr-io
Copy link
Owner Author

btzr-io commented Sep 4, 2020

First draft of Pages hook:

const currentPages =  usePages()
// Returns an array of the current image / images to render
[
  { index: 3, url: 'blob:image_url_soruce', name: 'page_0004.jpeg' }
]

// Note: if `layout` mode is set to `LAYOUT_MODE.BOOK` it will also return the next page
[
  { index: 3, url: 'blob:image_url_soruce', name: 'page_0004.jpeg' },
  { index: 4, url: 'blob:image_url_soruce', name: 'page_0005.jpeg' }
]

// Basic render example:
<div>
    { pages.map((page, key) => {
          return (<img src={page.url} height={500} key={key} />)
     })}
 </div>

@btzr-io
Copy link
Owner Author

btzr-io commented Sep 4, 2020

New react hook implemented: useEncrypted(), to handle encrypted archives: #26 (comment)

@btzr-io
Copy link
Owner Author

btzr-io commented Sep 6, 2020

Hooks are now part of the new villain-react/sdk module

@btzr-io btzr-io closed this as completed Sep 6, 2020
@btzr-io btzr-io unpinned this issue Sep 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant