summaryrefslogtreecommitdiff
path: root/storybook/toggle-storybook.tsx
diff options
context:
space:
mode:
authorKirill Rogovoy <[email protected]>2021-07-20 21:24:52 +0300
committerKirill Rogovoy <[email protected]>2021-07-20 21:24:52 +0300
commit5f4611d65e40eae3ca6191a15f68d69ea5a1c4cb (patch)
tree273dfc086444533d86d580961c92ba8d14781a67 /storybook/toggle-storybook.tsx
parentf0bf4e7afdcd8b02a62be45ab3e7d047ed865a79 (diff)
WIP
Diffstat (limited to 'storybook/toggle-storybook.tsx')
-rw-r--r--storybook/toggle-storybook.tsx51
1 files changed, 0 insertions, 51 deletions
diff --git a/storybook/toggle-storybook.tsx b/storybook/toggle-storybook.tsx
deleted file mode 100644
index 301695a..0000000
--- a/storybook/toggle-storybook.tsx
+++ /dev/null
@@ -1,51 +0,0 @@
-import React, { useState, useEffect } from 'react'
-import { DevSettings } from 'react-native'
-import { loadString, saveString } from '../app/utils/storage'
-
-/**
- * Toggle Storybook mode, in __DEV__ mode only.
- *
- * In non-__DEV__ mode, or when Storybook isn't toggled on,
- * renders its children.
- *
- * The mode flag is persisted in async storage, which means it
- * persists across reloads/restarts - this is handy when developing
- * new components in Storybook.
- */
-export function ToggleStorybook(props) {
- const [showStorybook, setShowStorybook] = useState(false)
- const [StorybookUIRoot, setStorybookUIRoot] = useState(null)
-
- useEffect(() => {
- if (__DEV__ && DevSettings) {
- // Load the setting from storage if it's there
- loadString('devStorybook').then((storedSetting) => {
- // Set the initial value
- setShowStorybook(storedSetting === 'on')
-
- // Add our toggle command to the menu
- DevSettings.addMenuItem('Toggle Storybook', () => {
- setShowStorybook((show) => {
- // On toggle, flip the current value
- show = !show
-
- // Write it back to storage
- saveString('devStorybook', show ? 'on' : 'off')
-
- // Return it to change the local state
- return show
- })
- })
-
- // Load the storybook UI once
- setStorybookUIRoot(() => require('./storybook').StorybookUIRoot)
- })
- }
- }, [])
-
- if (showStorybook) {
- return StorybookUIRoot ? <StorybookUIRoot /> : null
- } else {
- return props.children
- }
-}