Skip to content

Commit

Permalink
Updates from PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hgray-instawork committed Feb 7, 2024
1 parent 5acaffe commit 98b5cfb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
23 changes: 11 additions & 12 deletions demo/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,33 @@ import { NavigationContainer } from '@react-navigation/native';

const NAMESPACE_URI = 'https://instawork.com/hyperview-set-navigator-source';

/**
* Define expected values
*/
enum NavigationSource {
HXML = 'hxml',
EXTERNAL = 'external',
HYPERVIEW = 'hyperview',
}

export default () => {
const [useHXML, setUseXML] = useState<boolean>(false);
const [navigationSource, setNavigationSource] = useState<NavigationSource>(
NavigationSource.EXTERNAL,
);

/**
* Create a custom behavior to toggle using HXML to define the navigator hierarchy
*/
const setNavigatorSrcBehavior = {
const setNavigatorSourceBehavior = {
action: 'set-navigator-source',
callback: (element: Element) => {
const source = element.getAttributeNS(NAMESPACE_URI, 'source');
if (source === NavigationSource.HXML) {
setUseXML(true);
if (source === NavigationSource.HYPERVIEW) {
setNavigationSource(NavigationSource.HYPERVIEW);
} else if (source === NavigationSource.EXTERNAL) {
setUseXML(false);
setNavigationSource(NavigationSource.EXTERNAL);
}
},
};

// Pass the behavior to the HyperviewScreen
HyperviewScreen.Behaviors = [setNavigatorSrcBehavior];
HyperviewScreen.Behaviors = [setNavigatorSourceBehavior];

return (
<SafeAreaProvider>
Expand All @@ -66,10 +65,10 @@ export default () => {
}}
>
<NavigationContainer>
{useHXML ? (
{navigationSource == NavigationSource.HYPERVIEW ? (
// Hyperview will build a Navigator structure from the HXML document
<Hyperview
behaviors={[setNavigatorSrcBehavior]}
behaviors={[setNavigatorSourceBehavior]}
entrypointUrl={Constants.ENTRY_POINT_NAV_URL}
fetch={fetchWrapper}
formatDate={formatDate}
Expand Down
2 changes: 1 addition & 1 deletion examples/_includes/base.xml.njk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{% if show_hxml_toggle %}
<view style="Header__Switch">
<text style="Switch__Label">HXML Navigator</text>
<switch id="navigator-switch" xmlns:set-navigator-source="https://instawork.com/hyperview-set-navigator-source" trigger="change" action="set-navigator-source" set-navigator-source:source={% if hxml_toggle_enabled %} "external" {% else %} "hxml" {% endif %} value={% if hxml_toggle_enabled %} "on" {% else %} "off" {% endif %}/>
<switch id="navigator-switch" xmlns:set-navigator-source="https://instawork.com/hyperview-set-navigator-source" trigger="change" action="set-navigator-source" set-navigator-source:source={% if hxml_toggle_enabled %} "external" {% else %} "hyperview" {% endif %} value={% if hxml_toggle_enabled %} "on" {% else %} "off" {% endif %}/>
</view>
{% endif %}
</header>
Expand Down

0 comments on commit 98b5cfb

Please sign in to comment.