Skip to main content

Events

You can attach and subscribe to events in order to run logic in your app when something happens in StorifyMe Snaps Editor. This way, you can:

  • show loading animation while editor loads
  • react on any error,
  • intercept snap saved and handle logic localy,
  • and many other use cases

Example code

The best way to attach listeners is by overriding native StorifyMe events:

import {
StorifyMeEnv,
StorifyMeSnaps,
StorifyMeSnapsEventListener,
} from 'react-native-storifyme-snaps';

export default function App(): JSX.Element {
const initSnapsSDK = () => {
// Call the specific Android method
StorifyMeSnaps.init(
'ACCOUNT_ID',
'API_KEY',
'ENV'
);

// Listen to events
StorifyMeSnapsEventListener.onEditorLoaded(() => {
console.log('StorifyMe Snap Editor opened');
});
StorifyMeSnapsEventListener.onEditorLoadFailed((error: any) => {
console.log('Error happened in StorifyMe Snap Editor.');
});
StorifyMeSnapsEventListener.onEditorClosed(() => {
console.log('StorifyMe Snap Editor closed.');
});
StorifyMeSnapsEventListener.onSnapSaved((snapId: any) => {
console.log(`New StorifyMe Snap created with ID: ${snapId}`);
});
};

initSnapsSDK();

return (
<App>
<Button
title="Open Snaps Editor"
onPress={openSnapsEditor}
color="#000000"
disabled={false}
accessibilityLabel="Open Snaps Editor"
/>
</App>
);
}

onEditorLoaded()

onEditorLoaded method is invoked when the Snaps editor loads successfully.

StorifyMeSnapsEventListener.onEditorLoaded(() => {
console.log('StorifyMe Snap Editor opened');
});

onEditorLoadFailed()

onEditorLoadFailed method is invoked when the Snaps editor fails to load successfully.

StorifyMeSnapsEventListener.onEditorLoadFailed((error: any) => {
console.log('Error happened in StorifyMe Snap Editor.');
});

onEditorClosed()

onEditorClosed method is invoked when the Snaps editor is closed.

StorifyMeSnapsEventListener.onEditorClosed(() => {
console.log('StorifyMe Snap Editor closed.');
});

onSnapSaved()

onSnapSaved method is invoked when the Snaps is saved and the editor is closing.

StorifyMeSnapsEventListener.onSnapSaved((snapId: any) => {
console.log(`New StorifyMe Snap created with ID: ${snapId}`);
});