For a side project I’m building an extension for Safari on iOS using React Native. This actually involves writing more Objective-C than I’m used to (I suck at Objective-C), so I wrote a tutorial to remind myself, and you the lucky reader, about all the pitfalls and how to avoid them.
The instructions, along with sample code, are on Github at https://github.com/shaneosullivan/ReactNativeExampleBrowserExtension
I’ve come up against a common problem when writing React components that depend on a 3rd party JS and CSS files.
Do I load these 3rd party files every time, and pay the performance cost, or manually hack a way to load them when my component is first used?
I decided to fix this properly, which has resulted in a simple React component I’ve open sourced called ReactDependentScript. You simply wrap your components in <ReactDependentScript …. >, telling it what JS and CSS files to load, and it loads them first, and only when they successfully load does it render the child components.
It also supports taking a function prop to call to render the child components lazily.
For example, you can load jQuery, and then render jQuery plugins or simply use the $ function.
You can do more interesting things like load the Stripe JS code for their Checkout flow.
Have a play with it at https://github.com/shaneosullivan/ReactDependentScript, or install it from NPM (https://www.npmjs.com/package/react-dependent-script) with
yarn add react-dependent-script
It’s MIT licensed so use it as you wish. Please feel free to provide feedback or changes through Github.
I recently found my old Palm Pre 3 (the unreleased on I received as a gift), and was amazed at how good it still felt. Here’s a quick video I made of some of it’s features, and one of my favourite apps that I built, Mazer
Many years ago I wrote a search engine site called Chofter.com, that I thought was pretty cool. It pulled together search results from Google, Bing, Flickr and many other search services all into one UI.
Time has moved on, and most of the APIs have been shut down, so I’ve decided to shutter the site. At the same time, the internet server for my alma mater on which I served all my academic research has shut down after 25 years in operation.
So, I’ve thrown together a simple site for Chofter.com which provides links to many of the things I’ve built over the years that still have some value (it was a shock to see how useless stuff gets over 15 years!), including my mobile apps for non-dead platforms, my robotics research and Voronoi graph code, and more.
A common problem I’m come across is that of similar files being scattered around my computer by various services, that I wished were all located in the same place. For example, my iPad syncing photos to Dropbox’s “Camera Uploads” folder, whereas my phone syncing with the Mac’s Photos hidden folder, since I plug it in much more often.
My preference is that they would all just be in a single folder. But I don’t want to do this manually, on a regular basis.
To fix this I’ve written a simple script that can be installed on a Mac as a service. It is called folder-backup-service, and can be downloaded either as a ZIP file, or checked out out using Git (if you’re more of a web engineer) from GitHub at https://github.com/shaneosullivan/folder-backup-service .
For usage, see the README file.
Some benefits of using this include
- Keep the amount of space used in Dropbox low. As soon as any device puts a file in a Dropbox folder you’ve specified, and it syncs to your computer, it will be moved off Dropbox to your local machine.
- Should keep the local cache usage on mobile devices by Dropbox low, rather than using up gigabytes on iPads and iPhones.
- Makes it easier to find your original images when syncing through Photos, rather than having to dig around for them in the hidden folders that Apple insists on storing them in.
This is open source, licensed with MIT, and I’m very open to people sending pull requests if you’re interested in getting the service working with operating systems other than Mac.
Over the past few months I have been building an app for a friend called Dark Legacy Comics in my spare time. I previously wrote about the iOS version I released, and now I’m very happy to say that I’ve launched the Android version!
You can get the app from https://play.google.com/store/apps/details?id=com.chofter.dlc, using any Android device.
As with the iOS version, the app costs $2, and all proceeds go the author of the comic to help with funding his site costs. Given the comic gets about 200k visitors per month, it’s quite expensive!
React Native is awesome, but the docs leave something to be desired, particularly for Android (the RN team is working on it!). I recently wanted to get started on building an Android version of the completed iOS app I previously shipped using React Native, but it turned out to be an overly painful process. The docs assume knowledge of Android development, which I do not have, so here are the steps I used to get up and running on my Mac.
- React Native version 0.32
- Mac OSX 10.11.6 (15G1004)
- javac version 1.8.0_011
- Follow the instructions for installation in Dependencies for Mac & Android.
- Open Android Studio from Applications, step through the setup wizard to download all the packages it needs (about 250MB)
- To run the emulator, you need to create a Virtual Device
– Use AVD Manager to create a virtual device (https://developer.android.com/studio/run/managing-avds.html). I chose to use a Nexus 5X emulator for no other reason as it was the default selected one.
– Run that device by clicking on the green Play button
- In your terminal, change directory to the root of your React Native app, and run
If at this point your React Native app shows up in your emulator, congrats, you’re now a React Native Android developer!
If not, read on.
You might see this error:
Could not run adb reverse: spawnSync
If so, add the following to ~/.bash_profile if not already there:
from the root of your app again. (From Stack Overflow: http://stackoverflow.com/questions/38835931/react-native-adb-reverse-enoent).
If you get the error
failed to find target with hash string ‘android-23’
try deleting the folder
and running the command again (from http://stackoverflow.com/questions/33417537/failed-to-find-target-with-hash-string-android-23). This apparently worked for some people, but not me.
You should install:
- “SDK Platform” for android-23
- Go to Tools/Android/SDK Manager
- Click the “SDK Platforms” tab, if not already selected
- Check the box for Android 6.0, which is API version 23
- Android SDK Build tools for version 23 (I installed 3 of them, see screenshot)
- Go to Tools/Android/SDK Manager
- Click the SDK Tools tab
- Check the “Show Package Details” box in the bottom right
- Under “Android SDK Build Tools” check all boxes for anything with version 23.
This got me past this error.
I then got the errors:
<project folder>/android/app/src/main/java/com/dlc/MainActivity.java:35: error: method does not override or implement a method from a supertype
<project folder>/android/app/src/main/java/com/dlc/MainActivity.java:39: error: constructor FBSDKPackage in class FBSDKPackage cannot be applied to given types;
found: no arguments
reason: actual and formal argument lists differ in length
It turns out I had generated my project on an earlier version of React Native, as I was working on the iOS version first, and the Android code it generated was no longer compatible with React Native v0.32. To fix this:
- Create a temporary folder
- mkdir ~/tempFolder
- cd ~/tempFolder
- Now create a new React Native application with the exact same name as your application in that folder. This is important as the React Native tools embed that in a number of files that they generate.
- react-native init MyAppName
- Rename the folder in your original app “/android/app” to something else, e.g. “/android/app_old_and_busted”
- Copy the folder ~/tempFolder/MyAppName/android/app to the “android” folder in your app.
- run the command “react-native run-android” from the root of your app again.
- Woohoo, it worked for me!
I’ve been a fan of the React Native framework for a while, even ignoring the fact it’s built by my colleagues at Facebook. However since I spend my work days talking to engineers rather than coding these days, I haven’t had a chance to build anything real with it. While I had some time off recently I fixed that, and built a fun new app for a friend, Dark Legacy Comics, now available on the Apple App Store.
The process was nowhere as smooth as it needs to be, given I ran into many tricky roadblocks with upgrading versions, importing 3rd party libraries, weird iOS build errors and more. Still, with a little perseverance and quite a bit of cursing, I got it all working. So, try it out (sorry it’s not free, all proceeds to the author of the comic, but he’s awesome and more than deserves it after 10 years of hard work) and let me know what you think!
I like to keep up with discussions about the Tesla Model S in their online forum, but this is very difficult to do on a mobile device, since it it not optimized for that, and still focuses on a desktop layout.
So I fixed it! Behold the mobile Telsa Motors forum – http://chofter.com/tesla .
Open this on a mobile device and enjoy browsing through all the comment threads.
Since I do not work for Tesla and don’t have access to their forum code there are some limitations:
- It’s read only. If you want to comment you have to go to their site.
- It can’t show private posts, so only public posts are visible
- To save on server costs, it refreshes every 10 minutes, so sometimes may not be as up to date as the real forum. This should be mostly fine though
Check it out at http://chofter.com/decode
It’s a simple single page application, and can be used as a good example of how to structure a simple ReactJS application. The source code is available on GitHub at https://github.com/shaneosullivan/react-url-decoder .