Skip to content

Instantly share code, notes, and snippets.

@attentive
Last active February 12, 2019 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save attentive/a6892245133403f02f8859c7db57c022 to your computer and use it in GitHub Desktop.
Save attentive/a6892245133403f02f8859c7db57c022 to your computer and use it in GitHub Desktop.
How to integrate react-native-splash-screen with ClojureScript
(ns rnss.core
(:require [oops.core :refer [oget ocall]]
[reagent.core :as r]
["react-native" :as RN]
["react-native-splash-screen" :as RNSS]))
;; The code below depends on the existence of a separate splash screen
;; layout in your app, as per the react-native-splash-screen doco.
;; This sample shows only how to reference the splash screen library and
;; activate it when your React Native app's main component is mounted.
;; Somewhere in your code (for re-natal code generation)
(js/require "react-native-splash-screen")
;; Some sort of React component to render (your app)
(def View (r/adapt-react-class (oget RN :View)))
;; Wrappers to manipulate splash screen
(defn hide-splash-screen [] (ocall (oget RNSS :default) :hide))
(defn show-splash-screen [] (ocall (oget RNSS :default) :show))
;; In your CLJS application's initialisation logic (Reagent sample below)
(defn App []
(r/create-class
{:reagent-render
(fn []
[View])
:component-did-mount
(fn [this]
(hide-splash-screen))})) ;; Hide the splash after the App component mounts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment