• Stars
    star
    359
  • Rank 117,555 (Top 3 %)
  • Language
    Clojure
  • Created over 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An example project to get you started with React Native using shadow-cljs in 3 minutes

React Native using shadow-cljs in 3 minutes

The fastest way a ClojureScript coder can get started with React Native development. Prove me wrong.

This is an example project, only slightly beyond Hello World, using: shadow-cljs, React Native, Expo, Reagent, and re-frame.

Check this video out for a demo of this project.

ClojureScript ❤️ React Native

Follow along to get started. There are instructions for Calva, Emacs/CIDER, Cursive, and the command line. It is assumed you have Java and Node installad as well as dev tool chains for the platforms you are targeting. (If you are targeting the Web, then Chrome is enough.)

Installing

To facilitate that you can easily try this out without installing anything globally on your machine, this project installs everything it needs locally in node_modules. Then npx is used to execute tools like expo-cli.

To install dependencies, and setup the project, run:

  1. npm i

From there use your favorite editor and/or the prompt.

Using VS Code + Calva

Assuming you have installed the Calva extension in VS Code:

Build and start the app, and connect Calva

  1. Open the project in VS Code. Then:
  2. Run the Calva command Start a Project REPL and Connect (aka Jack-in)
    1. Wait for shadow to build the project.

Start Expo

  1. Then Run Build Task. This will start Expo and the Metro bundler. Wait for expo to show its menu options in the terminal pane.
  2. In the expo menu press w for open web.

The app now should be running in your web browser and Calva automatically connects to it. Confirm this by evaluating something like this in Calva (from a cljs file or in the REPL window):

(js/alert "Hello world!")

You should see the alert pop up where the app is running.

Of course you should try to fire up the app on all simulators, emulators and phones you have as well. Please note that Calva will only be connected to one of your apps at a time, and it is a bit arbitrary which one. Use (js/alert) to check this.

Using Emacs with CIDER

Open Emacs and a bash shell:

  1. Run npx shadow-cljs compile :app to perform an initial build of the app.

  2. In Emacs open one of the files in the project (deps.edn is fine)

  3. From that buffer, do cider-jack-in-clojurescript [C-c M-J] to launch a REPL. Follow the series of interactive prompts in the minibuffer:

    1. select shadow-cljs as the command to launch
    2. select shadow as the repl type
    3. select :app as the build to connect
    4. and optionally answer y or n to the final question about opening the shadow-cljs UI in a browser. At this point shadow-cljs will be watching the project folder and running new builds of the app if any files are changed. You'll also have a REPL prompt, however the REPL doesn't work because it isn't connected to anything. The app isn't running yet.
  4. In a shell run npm run ios (same as npx expo start -i). This starts the Metro bundler, perform the bundling, launch the iPhone simulator, and transmit the bundled app. Be patient at this step as it can take many seconds to complete. When the app is finally running expo will display the message:

    WebSocket connected!
    REPL init successful
    
  5. Once you see that the REPL is initalized, you can return to Emacs and confirm the REPL is connected and functional:

    cljs.user> (js/alert "hello world!")

    Which should pop-up a modal alert in the simulator, confirming the app is running and the REPL is connected end to end.

Using IntelliJ + Cursive REPL

  1. Follow the instructions specified in Or the Command line.
  2. Create a Maven POM using shadow-cljs pom, as described in the Shadow doc.
  3. There are now two options
    1. If you already have a project open, open the project in IntelliJ using File | New | Project from existing sources... and indicating the pom.xml file.
    2. If you're at the welcome screen, press the "Open" button and navigate to the pom.xml.
  4. Ensure the project has an SDK configured using File | Project Structure, and checking under Project.
  5. The project comes with a REPL run configuration called "REPL". Run the REPL using the Run | Run 'REPL' menu item, or the toolbar button.
  6. Run the commands in Using ClojureScript REPL

Or the Command line

$ npm i
$ npx shadow-cljs watch app
# wait for first compile to finish or expo gets confused
# on another terminal tab/window:
$ npm start

This will run Expo DevTools at http://localhost:19002/

To run the app in browser using expo-web (react-native-web), press w in the same terminal after expo devtools is started. This should open the app automatically on your browser after the web version is built. If it does not open automatically, open http://localhost:19006/ manually on your browser.

Note that you can also run the following instead of npm start to run the app in browser:

# same as npx expo start --web
$ npm run web

# or

# same as npx expo start --web-only
$ npm run web-only

Using ClojureScript REPL

Once the app is deployed and opened in phone/simulator/emulator/browser, connect to nrepl and run the following:

(shadow/nrepl-select :app)

NB: Calva users don't need to do ^ this ^.

To test the REPL connection:

(js/alert "Hello from Repl")

Command line CLJS REPL

Shadow can start a CLJS repl for you, if you prefer to stay at the terminal prompt:

$ npx shadow-cljs cljs-repl :app

Disabling Expo Fast Refresh

You will need to disable Fast Refresh provided by the Expo client, which conflicts with shadow-cljs hot reloading. You really want to use Shadow's, because it is way better and way faster than the Expo stuff is.

For the iOS and Android there is a Disable Fast Refresh option in the development menu. NB: Often you need to first enable it and then disable it.

Production builds

A production build involves first asking shadow-cljs to build a release, then to ask Expo to work in Production Mode.

  1. Kill the watch and expo tasks.
  2. Execute shadow-cljs release app
  3. Start the expo task (as per above)
    1. Enable Production mode.
    2. Start the app.

Using EAS Build

expo build is the classic way of building an Expo app, and eas build is the new version of expo build. Using EAS Build currently requires an Expo account with a paid plan subscription.

The steps below provide an example of using EAS Build to build an apk file to run on an Android emulator or device.

  1. Install the latest EAS CLI by running npm install -g eas-cli
  2. Log into your Expo account
  3. Configure EAS Build in your project with eas build:configure.
  4. Make your eas.json file contents look like this:
    {
      "build": {
        "production": {},
        "development": {
          "distribution": "internal",
          "android": {
            "buildType": "apk"
          },
          "ios": {
            "simulator": true
          }
        }
      }
    }
  5. Commit your changes, run eas build --profile development, and follow the prompts.
  6. Navigate to the URL given by the command to monitor the build. When it completes, download the apk and install it on your device or emulator.

See the EAS Build docs for more information.

If you want to use EAS Build with a project not based on this template, see this PR for information about how your project can be set up to avoid an error during the build process.

Note: The eas-build-pre-install.sh script makes EAS install Java in the MacOS environment when running a build for iOS. This ensures that shadow-cljs can be run in the EAS pipeline to build your ClojureScript code.

React Navigation included

The app is setup to use React Navigation. If you don't need that in your app, just remove it.

Happy Hacking! ❤️

Please don't hesitate to star the project repository.

More Repositories

1

SketchDistributor

Sketch plugin that distributes selected objects vertically or horizontally with a given spacing
Shell
355
star
2

rich4clojure

Practice Clojure using Interactive Programming in your editor
Clojure
204
star
3

SketchSeparateShapes

A Sketch-app plugin that does a ”boolean” separate operation on two selected shapes. Like divide in Pathfinder in Adobe Illustrator.
JavaScript
166
star
4

clerk

In-page navigation (scrolling) for ClojureScript SPAs.
Clojure
71
star
5

clojure-get-started-mini

A Clojure Get Started mini project template
Clojure
35
star
6

taplet

Clojure/ClojureScript utilities for tapping things. let> macro, and #t reader tag
Clojure
32
star
7

GWT-Relative-Time

Bringing timestamps for humans to your GWT client
Java
24
star
8

reagent-bidi-accountant-example

Demonstrating a client side routing recipe for reagent projects
Clojure
23
star
9

shadow-w-backend

A tiny example project for setting up development using nREPL and shadow-cljs.
Clojure
20
star
10

scad-clj-workflow

Interactive 3D Modeling with Clojure
Clojure
19
star
11

FlexGauge

A standalone Gauge component for Flex 4
ActionScript
19
star
12

clojure-clr-starter

A Dockerized mini-project for testing ClojureCLR
Clojure
18
star
13

get-started-with-clojure

Learn Clojure and Interactive Programming – Zero install
15
star
14

shadow-bare-bones

A mini-project to quickly get started with ClojureScript for hacking on a browser app
Clojure
14
star
15

js2clj2js

A demo about being cautious with clj->js and js->clj
Clojure
12
star
16

clojure-exercism-template

Learn more Clojure and Interactive Programming with Exercism in the browser
Dockerfile
11
star
17

wally-example

An example project for end to end testing with Wally, a Clojure Wrapper for Playwright
Clojure
10
star
18

pirate-lang

Zero Install Calva + Gitpod + VNC + deps.edn demo project
Clojure
9
star
19

backseat-driver

The Hackable VS Code AI Assistant
Clojure
8
star
20

x-meta-image

REPL Playground for adding back article info to links shared on X/Twitter
Clojure
7
star
21

awesome-krell-project

A ClojureScript React Native (cljsrn) Example Project using Krell
Java
7
star
22

Sanskrit

Tore Darell's Sanskrit with some richer formatting support
JavaScript
6
star
23

on-the-code-again-eratosthenes

Clojure Eratosthenes with On The Code Again and PEZ
Clojure
6
star
24

Bots

My Robocode Bots
Java
6
star
25

deps-edn-figwheel

An attempt at a skeleton for building Clojurescript apps with Figwheel and Clojure CLI
Clojure
5
star
26

paste-replaced

A VS Code extension for pasting text replaced using configurable regular expressions.
Clojure
5
star
27

shadow-portal

A template project for using shadow-cljs and Portal together
Clojure
4
star
28

metronomic

iPhone metronome app
Objective-C
4
star
29

london-clojurians-joyride

Slides and materials for the London Clojurians Meetup about Joyride
Clojure
4
star
30

joyride-aoc-2022

Script VS Code to solve Advent of Code this year
Clojure
3
star
31

a-quil-workflow

An example project for playing with Quil in the REPL
Clojure
3
star
32

Flex4GroupIcon

A Flex 4 component for rendering avatars from a list with URLs
ActionScript
3
star
33

prettier-plugin-clojure

An (almost) indentation-only, non-configurable, Prettier Plugin for Clojure and ClojureScript (and any sufficiently similar implementations).
Clojure
3
star
34

ghost-chase-condition

Chasing a performance-eating ghost down the JVM rabbit hole
Java
2
star
35

wexio-lambda-sessions

”Slides” for Wexio Lambda Sessions Clojure presentation May 6 2021
Clojure
2
star
36

clojure-zero

A minimal Clojure project, to fill with your own code. Ready for use in the browser with full IDE (VS Code + Calva) support
Clojure
2
star
37

black-and-gold

Rust
2
star
38

Mobile-Sharer

Plugging a hole in the Facebook for iPhone app
Objective-C
2
star
39

VotingCattleCaptions

Captions for Message to the Voting Cattle, by Larken Rose
1
star
40

SketchPluginShortcuts

An inventory of Sketch plugin shortcuts
CSS
1
star
41

Doodulum

Playing with pendulum physics in Flash
JavaScript
1
star
42

Three20Issue594

Exposing app crashing introduced by dev branch 1.0.6
Objective-C
1
star
43

TreasureHunt

Objective-C
1
star
44

clojure-java

Java
1
star
45

arkiv-skolplattformen

TypeScript
1
star
46

Sandy3DGallery

An experiment with using Sandy3D for a Cooliris inspired Flickr Gallery
JavaScript
1
star
47

forgets

JavaScript
1
star
48

linkedin-paste-image

JavaScript
1
star
49

Mini-Collectors

For collectors of LEGO Minifigures
Objective-C
1
star
50

quil-cljs-calva-template

A basic `lein new quil` project with Calva dependencies added
Clojure
1
star
51

clojurescript-reactive-spa-scroll-restore-example

A scroll restore recipe for history navigation scroll restoration in cljs reactive web apps
Clojure
1
star
52

minimal-reveal-deps

Clojure
1
star
53

seatbelt

A test runner for your VS Code extensions and/or Joyride scripts.
Clojure
1
star
54

my-first-macroquad-game

Rust
1
star
55

magick-pango-babashka

A Docker image to power your picture + text compostions
Dockerfile
1
star