Skip to content

Add route params to Drawer screen component props #26

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

Closed
wants to merge 4 commits into from
Closed

Conversation

DCKT
Copy link
Contributor

@DCKT DCKT commented Feb 14, 2020

Hello,

It looks like you can access to params from a drawer too

@idkjs
Copy link
Contributor

idkjs commented Feb 20, 2020

Hi @DCKT! Do you have an example that you are running this against that I can look at?

@DCKT
Copy link
Contributor Author

DCKT commented Feb 21, 2020

Hello @idkjs

I can't link you the repo but here is some code :

I have a generic view to display pdf file

module AuthenticatedDrawer = {
  module M = {
    type params = {
      url: string,
      filename: string,
    };
  };
  include Drawer.Make(M);
};

The declaration of my navigator :

<Navigator
      drawerWidth={() => 280.}
      drawerContent={props => <DrawerContent navigation=props##navigation />}>
      <Screen name="Deliveries" component=DeliveriesStack.make />
      <Screen name="PdfViewer" component=PdfViewerScreen.make />
</Navigator>;

The PdfViewerScreen :

[@react.component]
let make =
    (
      ~navigation,
      ~route:
         ReactNavigation.Core.route(Navigators.AuthenticatedDrawer.M.params),
    ) => {
  let url = route.params->Option.map(p => p.url)->Option.getWithDefault("");
  let filename =
    route.params->Option.map(p => p.filename)->Option.getWithDefault("");

  <>
    <Paper.Appbar.Header dark=true>
      <Paper.Appbar.BackAction
        onPress={Navigators.RootStack.Navigation.goBack(navigation)}
      />
      <Paper.Appbar.Content title={filename->React.string} />
    </Paper.Appbar.Header>
    <ReactNativeViewPdf
      fadeInDuration=250.0
      style=styles##root
      resource=url
      resourceType=`url
      onError={_err => {
        [%log.error "onError viewPDF"; ("error", _err)];
        ();
      }}
    />
  </>;
};

@MoOx
Copy link
Member

MoOx commented Feb 28, 2020

I landed all separate relevant commit into master. Try to make separate PR next time :D

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.

4 participants