Category: Tools

Story

So you have an awesome layout in your app and some of your view components aren’t aligned correctly or seem to have weird margins. We’ve all been there, and while this tip is not going to let you fix that really quick. It will help you to visualize how the layout has been drawn using the native views. This is applicable to any UI built on Android, including: NativeScript, ReactNative, Xamarin, etc. Anything that renders native UI.

Story

I was recently working on a project and multiple collaborators started to contribute to. All seemed fine until one day, I synced up with the master branch and had 100 warnings pop up in VSCode. I thought about buying my hot dog cart and moving to a beach area finally.

Being totally honest, that cart near the beach looks way more fun than sitting behind a desk staring at a beam of light sucking my soul away sometimes, but that’s just me. You are different and still love programming, because you’re young and full of energy. You’ll mature once you realize you attend meetings that could have been emails for years.

At any rate, lets get back to the issue.

So here I was staring at 100+ warnings all related to TSLint. At first, I thought, “Damn, I’m gonna Macho Man Randy Savage elbow drop someone.”

I then started thinking “how could they commit with these warnings?”, it turned out I had the TSLint extension for VSCode installed and they did not, so they never seen the warnings as they worked on the project. Worse yet, nothing was in place to warn them or prevent the code from being committed.

The Solution

We already use a precommit hook that runs Prettier against files so it was a simple step to add tslint to run during the precommit hook we have in our project.

The above basically runs on all the TypeScript files and runs `tslint` then `prettier` and last `git add`.

As for how this gets executed I have a brief write up on adding a precommit hook for Prettier. Which outlines the dependencies on `husky` and `lint-staged`. If you don’t want to look at that, then add the following as a script in your package.json `scripts` section:

"precommit": "lint-staged",

Be sure to add the dependencies to your project as well under the `devDependencies`: `lint-staged` and `husky`.

Now when someone tries to commit files to the repo their files will be ran against `tslint` (at this point I shouldn’t have to tell you that you need it inside your project). If all the tslint checks pass then the commit works, if not you’ll have errors with your git logs.

Where you been?

If you haven’t heard of Prettier you are missing out on one of the best tools for the javascript community. I’ve been hanging around on the outskirts of adopting Prettier because I’m very focused on TypeScript projects and initially there was no support for TypeScript. That was until 12 days ago when 1.4.0 was published. So now I’m diving head in on all projects to default with Prettier support. I’ll keep this brief, so let’s dive in.

The Steps

First, we need to add a few packages to our project as dev dependencies. Run the following from your terminal:

npm install prettier lint-staged husky --save-dev

You can use yarn if you’d like instead of npm to install the dev dependencies.

Second, open your project’s package.json and add the following script and object for lint-staged

Recently, I was asked, “How do you record your .gifs for your app demos and twitter images?” Well it’s really simple. I use a tool from Cockos Incorporated called LICEcap. They have a Windows and OSX version available for download.

Once you install the application, open up your app emulator and LICEcap. Then position LICEcap over your emulator and press the record button. Then when you are done, just stop the recording. BAM! You now have an awesome .gif to attach to your GitHub repos and to use on Twitter or wherever else you want to show your work off.

This is also a great tool for issues on GitHub. Have an issue, record your browser or emulator and attach a nice .gif showing the issue. This will help in your engagement tremendously. I’m always more inclined to assist users who provide detailed information on issues than those who simply say, “X is broken, fix ASAP!” Let’s be honest, this is how I react to those issues:

Happy Coding!

Just a legal disclaimer: I am not paid or endorsed by Cockos Inc. in any way, I wish I did have some endorsements… then I could be like Peyton Manning name dropping Budweiser in the SuperBowl 🙂