React Native, as seen on TV

Rate this content
Bookmark

You might have heard of React Native's Many Platforms vision, but what about TVs? Find out about the joys and challenges of developing for 7 platforms at once with a single codebase!

This talk has been presented at React Summit 2022, check out the latest edition of this React Conference.

FAQ

Just Watch is a TV guide for streaming services, helping users find where their favorite movies or TV shows are available, and providing notifications when new seasons are released.

Just Watch supports various platforms including iOS, Android, and TVs.

The main platforms for TV app development using React Native are Android TV, Fire TV, and tvOS.

React Native tvOS is a fork of the main React Native repository that provides specific functionality and features for building TV apps.

For LG TVs, Samsung TVs, and Xboxes, you need to build your app as an HTML app using React Native web while maintaining the same code base as other platforms.

Directional navigation or arrow key based navigation is a method where users interact with TV apps using their remote's arrow keys (up, down, left, right) and select button.

React Native tvOS provides props like focusable, unfocus, unblur, hasTVPreferredFocus, and next focus down/left/up/right to manage focus and navigation in TV apps.

In mobile app development, focus management is simpler, often just bringing up the keyboard for input fields. In TV app development, focus management is more complex, requiring navigation between components using directional keys.

Norwegian Spatial Navigation is a library used in React Native web for managing focus in TV apps. It uses unique focus keys and functions like setFocus to handle navigation.

TVs are generally underpowered compared to modern mobile phones, with slower CPUs and outdated browsers. Performance optimization is crucial to ensure smooth operation on older or less capable devices.

Michele Bonazza
Michele Bonazza
20 min
21 Jun, 2022

Comments

Sign in or register to post your comment.

Video Summary and Transcription

This Talk discusses TV app development using React Native, focusing on limitations and specific considerations. The speaker demonstrates how to fetch and display random dog images using React Native hooks. They also explain how to handle focus and spatial navigation in TV apps, including using focus keys and a spatial navigation library. The Talk emphasizes the importance of optimization and performance in TV app development and suggests using useMemo and useCallback to avoid unnecessary re-renders. The speaker concludes by mentioning job opportunities at JustWatch.
Available in Español: React Native, como se ve en la TV

1. Introduction to TV Apps Development

Short description:

In this part, Michele introduces Just Watch, a TV guide for streaming services, and shares their experience in finding information about TV apps development. They discuss the limitations and specific considerations for building TV apps using React Native, including directional navigation and the use of React Native tvOS and React Native web for different platforms.

Hi there, welcome to React Native as seen on TV. I'm Michele, I'm a software developer at Just Watch. What is Just Watch in case you don't know? It's the TV guide for streaming services. So if you don't know where your favorite movie or TV show is available, or if you want to get say a notification the next time a new season for your favorite TV show comes out, you can head over to our website or use one of our many apps, including not only iOS and Android, but also TVs.

So when I joined Just Watch, I didn't know much about TV apps development, and I honestly found it kind of hard to find information about it online. Because yes, there is a section that's dedicated to it on the React Native website, but there isn't that much. So last year, when the React team came up with this blog post titled the Many Platform Vision, I was all excited and thought, oh, nice, they're finally talking about TV apps development. But it turns out that they weren't. They were really talking about React Native Windows and Mac OS and VR, but no mention of TVs. So this thing here in the animation is not a TV in case you thought that, it's actually a desktop. So bummer.

So in my talk today, I'm going to talk to you about how you can build your TV apps using React Native. What's special about TV apps development compared to mobile app development. And finally, I'm going to give you a couple of small tips and tricks that you can use to make your app perform better in a constrained environment such as the TV environment. So when you're building for TVs, the three main platforms that you're going to target are Android TV and Fire TV, based on Android, and tvOS. For these, you can use React Native tvOS, which is a fork of the main React Native repo, which is kind of unfortunate because it means that it's always going to be a little behind, but it's being updated fairly regularly. And this React Native tvOS repo gives you a number of functionality and features that you can use to build your TV apps with. This is not the whole picture though, because if you want to target LG TVs and Samsung TVs or Xboxes like we do, you will need to build your app as an HTML app. And to do so while still using the same code base that you're using for the other platforms, you can use React Native web. So talking about things that are specific to TV apps development, there is definitely directional navigation or arrow key based navigation. Your users will interact with your app only using their remote. So their options are limited there. They can only go up, down, left, right, select, go back, unless they have an LG TV, which has its own magic remote. It's really called like that, which is a pointer based interface. But other than that, they will have this arrow key based navigation. React Native tvOS gives you this TV event handler that lets you intercept these key events. And it also gives you a number of props like focusable, unfocus, unblur. These work exactly like they do on pressable on the regular React Native repo. But also some that are specific to TV app development, such as hasTVPreferredFocus, which tells the OS which component should get focused by default when rendering your view. Or the next focus down, left, up, and right props.

2. TV App Development with React Native

Short description:

In this part, Michele discusses the complexity of focus in TV app development compared to mobile app development. They demonstrate a React Native app running on the Apple TV simulator and explain how to clear the code to develop TV apps with React Native. Michele also introduces a public API called Docs.io and explains how to fetch and display random dog images using React Native hooks.

And these are also used to tell the OS where focus should go, in this case, when users press the arrow keys. So compared to mobile app development, focus is a lot more complex. Usually with mobile apps, what you do is simply say, hey, if this input field is focused, please bring up the keyboard. Something like that. Not much more than that, usually.

So let's look at some code. I have a repo here, which I created using the React Native CLI, cloning this template, React Native template TypeScript TV. So if I launch Yarn iOS, this is going to bring up the Apple TV simulator and the regular React Native demo app. It looks a little weird with these colors. I'm not sure why. And aside from that, it's just your regular app. But you can see on the top right here, you can see that it's telling me when I'm pressing arrow keys, which one was pressed. This is React Native TV OS.

So let's clear everything inside here so I can show you how it is to develop TV apps with React Native. So I have my own styles, nothing fancy, just, yeah, they're my own. I'm importing them, and I'm clearing the imports. So now we have a blank canvas. Here we go. So I have this API, which is a public API called Docs.io. It's not mine. I'm just using it. I'm fetching 10 random images of dogs and giving them an ID based on their position in the array. So let's get them when the component is mounted. I'm using hooks. So dogs, set dogs. Let's have a useState, which is going to contain an array of images. We want to fetch it, so let's have a useEffect, which will actually fetch the dog images. Here we go. It's a promise. So when I get the result, I'm calling setDogs.