-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81aca95
commit d5c9f3a
Showing
16 changed files
with
103 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
packages/react-native-storybook/src/nativeModule/appendFile.ts
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
packages/react-native-storybook/src/nativeModule/getModule.ts
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
packages/react-native-storybook/src/nativeModule/getSherloDirectoryPath.ts
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
packages/react-native-storybook/src/nativeModule/getSherloModule.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { NativeModules, Platform } from 'react-native'; | ||
import base64 from 'base-64'; | ||
import utf8 from 'utf8'; | ||
import Constants from 'expo-constants'; | ||
|
||
import { normalizeFilePath } from './utils/normalizeFilePath'; | ||
|
||
const isExpoGo = Constants.appOwnership === 'expo'; | ||
|
||
const { RNSherlo } = NativeModules; | ||
|
||
interface SherloModule { | ||
mkdir: (path: string) => Promise<void>; | ||
appendFile: (path: string, base64: string) => Promise<void>; | ||
readFile: (path: string) => Promise<string>; | ||
writeFile: (path: string, data: string) => Promise<void>; | ||
} | ||
|
||
function getSherloModule(): SherloModule { | ||
if (RNSherlo === null) { | ||
if (isExpoGo) { | ||
return { | ||
mkdir: async () => {}, | ||
appendFile: async () => {}, | ||
readFile: async () => '', | ||
writeFile: async () => {}, | ||
}; | ||
} | ||
|
||
throw new Error( | ||
'@sherlo/react-natve-storybook: Sherlo native module is not accessible. Rebuild the app to link it on the native side.' | ||
); | ||
} | ||
|
||
const basePath = | ||
Platform.OS === 'android' | ||
? RNSherlo.getConstants().RNExternalDirectoryPath | ||
: RNSherlo.getConstants().RNDocumentDirectoryPath; | ||
|
||
return { | ||
appendFile: (filepath: string, contents: string) => { | ||
const b64 = base64.encode(utf8.encode(contents)); | ||
const normalizedFilePath = normalizeFilePath(`${basePath}/${filepath}`); | ||
|
||
return RNSherlo.appendFile(normalizedFilePath, b64); | ||
}, | ||
writeFile: (filepath: string, contents: string) => { | ||
const b64 = base64.encode(utf8.encode(contents)); | ||
const normalizedFilePath = normalizeFilePath(`${basePath}/${filepath}`); | ||
|
||
return RNSherlo.writeFile(normalizedFilePath, b64, { encoding: 'utf8' }); | ||
}, | ||
readFile: (filepath: string) => { | ||
const normalizedFilePath = normalizeFilePath(`${basePath}/${filepath}`); | ||
|
||
return RNSherlo.readFile(normalizedFilePath).then((b64: string) => { | ||
return utf8.decode(base64.decode(b64)); | ||
}); | ||
}, | ||
mkdir: (path: string) => { | ||
const normalizedFilePath = normalizeFilePath(`${basePath}/${path}`); | ||
|
||
return RNSherlo.mkdir(normalizedFilePath, {}); | ||
}, | ||
}; | ||
} | ||
|
||
export default getSherloModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1 @@ | ||
export { default as appendFile } from './appendFile'; | ||
export { default as mkdir } from './mkdir'; | ||
export { default as readFile } from './readFile'; | ||
export { default as writeFile } from './writeFile'; | ||
export { default as getSherloDirectoryPath } from './getSherloDirectoryPath'; | ||
export { default as getSherloModule } from './getSherloModule'; |
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
packages/react-native-storybook/src/nativeModule/readFile.ts
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
packages/react-native-storybook/src/nativeModule/writeFile.ts
This file was deleted.
Oops, something went wrong.
6 changes: 4 additions & 2 deletions
6
packages/react-native-storybook/src/runnerBridge/actions/create.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletions
8
packages/react-native-storybook/src/runnerBridge/actions/getConfig.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
packages/react-native-storybook/src/runnerBridge/actions/getState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
packages/react-native-storybook/src/runnerBridge/actions/updateState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 5 additions & 7 deletions
12
packages/react-native-storybook/src/runnerBridge/useRunnerBridge.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters