UNPKG

6.46 kBSource Map (JSON)View Raw
1{"version":3,"sources":["DrawerSidebar.tsx"],"names":["React","StyleSheet","View","NavigationActions","DrawerSidebar","PureComponent","routeKey","descriptor","props","descriptors","options","Error","focused","tintColor","route","drawerLabel","title","getScreenOptions","key","routeName","drawerIcon","navigation","closeDrawer","dispatch","navigate","render","ContentComponent","contentComponent","state","index","styles","container","style","contentOptions","drawerOpenProgress","routes","screenProps","getLabel","renderIcon","handleItemPress","drawerPosition","create","flex"],"mappings":";;;;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,UAAT,EAAqBC,IAArB,QAA4C,cAA5C;AACA,SACEC,iBADF,QAIO,kBAJP;;AAwBA;;;AAGA,MAAMC,aAAN,SAA4BJ,KAAK,CAACK,aAAlC,CAAuD;AAAA;AAAA;;AAAA,8CACzBC,QAAD,IAAsB;AAC/C,YAAMC,UAAU,GAAG,KAAKC,KAAL,CAAWC,WAAX,CAAuBH,QAAvB,CAAnB;;AAEA,UAAI,CAACC,UAAU,CAACG,OAAhB,EAAyB;AACvB,cAAM,IAAIC,KAAJ,CACJ,6DADI,CAAN;AAGD;;AAED,aAAOJ,UAAU,CAACG,OAAlB;AACD,KAXoD;;AAAA,sCAalC,CAAC;AAAEE,MAAAA,OAAF;AAAWC,MAAAA,SAAX;AAAsBC,MAAAA;AAAtB,KAAD,KAA0C;AAC3D,YAAM;AAAEC,QAAAA,WAAF;AAAeC,QAAAA;AAAf,UAAyB,KAAKC,gBAAL,CAAsBH,KAAK,CAACI,GAA5B,CAA/B;;AACA,UAAIH,WAAJ,EAAiB;AACf,eAAO,OAAOA,WAAP,KAAuB,UAAvB,GACHA,WAAW,CAAC;AAAEF,UAAAA,SAAF;AAAaD,UAAAA;AAAb,SAAD,CADR,GAEHG,WAFJ;AAGD;;AAED,UAAI,OAAOC,KAAP,KAAiB,QAArB,EAA+B;AAC7B,eAAOA,KAAP;AACD;;AAED,aAAOF,KAAK,CAACK,SAAb;AACD,KA1B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AAU,EAAE,KAAKzB,KAAL,CAAWa,UAFzB;AAGE,MAAA,WAAW,EAAE,KAAKb,KAAL,CAAWC,WAH1B;AAIE,MAAA,kBAAkB,EAAE,KAAKD,KAAL,CAAW0B,kBAJjC;AAKE,MAAA,KAAK,EAAEN,KAAK,CAACO,MALf;AAME,MAAA,aAAa,EACXP,KAAK,CAACO,MAAN,CAAaP,KAAK,CAACC,KAAnB,IAA4BD,KAAK,CAACO,MAAN,CAAaP,KAAK,CAACC,KAAnB,EAA0BX,GAAtD,GAA4D,IAPhE;AASE,MAAA,WAAW,EAAE,KAAKV,KAAL,CAAW4B,WAT1B;AAUE,MAAA,QAAQ,EAAE,KAAKC,QAVjB;AAWE,MAAA,UAAU,EAAE,KAAKC,UAXnB;AAYE,MAAA,WAAW,EAAE,KAAKC,eAZpB;AAaE,MAAA,cAAc,EAAE,KAAK/B,KAAL,CAAWgC;AAb7B,OADF,CADF;AAmBD;;AAzFoD;;AA4FvD,eAAepC,aAAf;AAEA,MAAM0B,MAAM,GAAG7B,UAAU,CAACwC,MAAX,CAAkB;AAC/BV,EAAAA,SAAS,EAAE;AACTW,IAAAA,IAAI,EAAE;AADG;AADoB,CAAlB,CAAf","sourcesContent":["import * as React from 'react';\nimport { StyleSheet, View, ViewStyle } from 'react-native';\nimport {\n NavigationActions,\n NavigationRoute,\n NavigationScreenProp,\n} from 'react-navigation';\nimport Animated from 'react-native-reanimated';\nimport {\n Scene,\n NavigationDrawerState,\n DrawerContentComponentProps,\n SceneDescriptorMap,\n} from '../types';\n\ntype Props = {\n contentComponent?: React.ComponentType<DrawerContentComponentProps>;\n contentOptions?: object;\n screenProps?: unknown;\n navigation: NavigationScreenProp<NavigationDrawerState>;\n descriptors: SceneDescriptorMap;\n drawerOpenProgress: Animated.Node<number>;\n drawerPosition: 'left' | 'right';\n style?: ViewStyle;\n};\n\n/**\n * Component that renders the sidebar screen of the drawer.\n */\nclass DrawerSidebar extends React.PureComponent<Props> {\n private getScreenOptions = (routeKey: string) => {\n const descriptor = this.props.descriptors[routeKey];\n\n if (!descriptor.options) {\n throw new Error(\n 'Cannot access screen descriptor options from drawer sidebar'\n );\n }\n\n return descriptor.options;\n };\n\n private getLabel = ({ focused, tintColor, route }: Scene) => {\n const { drawerLabel, title } = this.getScreenOptions(route.key);\n if (drawerLabel) {\n return typeof drawerLabel === 'function'\n ? drawerLabel({ tintColor, focused })\n : drawerLabel;\n }\n\n if (typeof title === 'string') {\n return title;\n }\n\n return route.routeName;\n };\n\n private renderIcon = ({ focused, tintColor, route }: Scene) => {\n const { drawerIcon } = this.getScreenOptions(route.key);\n if (drawerIcon) {\n return typeof drawerIcon === 'function'\n ? drawerIcon({ tintColor, focused })\n : drawerIcon;\n }\n return null;\n };\n\n private handleItemPress = ({\n route,\n focused,\n }: {\n route: NavigationRoute;\n focused: boolean;\n }) => {\n if (focused) {\n // @ts-ignore\n this.props.navigation.closeDrawer();\n } else {\n this.props.navigation.dispatch(\n NavigationActions.navigate({ routeName: route.routeName })\n );\n }\n };\n\n render() {\n const ContentComponent = this.props.contentComponent;\n\n if (!ContentComponent) {\n return null;\n }\n\n const { state } = this.props.navigation;\n\n if (typeof state.index !== 'number') {\n throw new Error(\n 'The index of the route should be state in the navigation state'\n );\n }\n\n return (\n <View style={[styles.container, this.props.style]}>\n <ContentComponent\n {...this.props.contentOptions}\n navigation={this.props.navigation}\n descriptors={this.props.descriptors}\n drawerOpenProgress={this.props.drawerOpenProgress}\n items={state.routes}\n activeItemKey={\n state.routes[state.index] ? state.routes[state.index].key : null\n }\n screenProps={this.props.screenProps}\n getLabel={this.getLabel}\n renderIcon={this.renderIcon}\n onItemPress={this.handleItemPress}\n drawerPosition={this.props.drawerPosition}\n />\n </View>\n );\n }\n}\n\nexport default DrawerSidebar;\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n },\n});\n"]}
\No newline at end of file