Events
You can attach and subscribe to events in order to run logic in your app when something happens in Snaps editor. This way, you can:
- show loading animation while editor loads
- react on any error,
- intercept snap saved and handle logic locally,
- and many other use cases
Example code
The best way to attach listeners is by running:
main.kt
StorifyMeSnaps.instance.eventListener = object : StorifyMeSnapsEventListener() {
override fun onEditorLoaded() {
Log.d(TAG, "StorifyMeSnaps: onEditorLoaded()")
}
override fun onEditorLoadFailed() {
Log.d(TAG, "StorifyMeSnaps: onEditorLoadFailed()")
}
override fun onEditorClosed() {
Log.d(TAG, "StorifyMeSnaps: onEditorClosed()")
}
override fun onSnapSaved(snapId: Long) {
Log.d(TAG, "StorifyMeSnaps: onSnapSaved(), snapId: $snapId")
}
}
onEditorLoaded()
onEditorLoaded
method is invoked when the Snaps editor loads successfully.
main.kt
StorifyMeSnaps.instance.eventListener = object : StorifyMeSnapsEventListener() {
override fun onEditorLoaded() {
Log.d(TAG, "StorifyMeSnaps: onEditorLoaded()")
}
}
onEditorLoadFailed()
onEditorLoadFailed
method is invoked when the Snaps editor fails to load successfully.
main.kt
StorifyMeSnaps.instance.eventListener = object : StorifyMeSnapsEventListener() {
override fun onEditorLoadFailed() {
Log.d(TAG, "StorifyMeSnaps: onEditorLoadFailed()")
}
}
onEditorClosed()
onEditorClosed
method is invoked when the Snaps editor is closed.
main.kt
StorifyMeSnaps.instance.eventListener = object : StorifyMeSnapsEventListener() {
override fun onEditorClosed() {
Log.d(TAG, "StorifyMeSnaps: onEditorClosed()")
}
}
onSnapSaved()
onSnapSaved
method is invoked when the Snaps is saved and the editor is closing.
main.kt
StorifyMeSnaps.instance.eventListener = object : StorifyMeSnapsEventListener() {
override fun onSnapSaved(snapId: Long) {
Log.d(TAG, "StorifyMeSnaps: onSnapSaved(), snapId: $snapId")
}
}