UNPKG

@applicaster/zapp-react-native-utils

Version:

Applicaster Zapp React Native utilities package

56 lines (45 loc) 1.57 kB
/* global tizen */ const isTizen = typeof tizen !== "undefined"; import { isVizioPlatform } from "@applicaster/zapp-react-native-utils/reactUtils"; import * as platformKeys from "./keysByPlatform"; import { Platform } from "react-native"; /* * Default web keys are replaced by platform specific keys * platformKeys[Platform.OS] should only include keys * that are unique to that platform, i.e. Exit: { keyCode: 10182 } */ export const KEYS = Object.assign( platformKeys["web"], platformKeys[Platform.OS] ); export const ARROW_KEYS = [ KEYS.ArrowUp, KEYS.ArrowLeft, KEYS.ArrowDown, KEYS.ArrowRight, ]; /** * Platform.OS currently identifies Vizio as LG_TV, therefore we are using isVizioPlatform to identify platform and add keys. */ if (isVizioPlatform()) { Object.assign(KEYS, platformKeys.vizio); } /** * In TizenOS we need to register all of the keys that we are going to use. * You need to register using the name Tizen has for the key. * So for example 2 is listed as { name: "2", code: 50 } * If we were to use keysByPlatform when we need to register what we call code: "2" */ if (isTizen) { const keyObjects = Object.entries(platformKeys.samsung_tv); const codes = keyObjects.reduce((accum, keyObj) => { const code = keyObj[1].code; // Tizen does not let you register back key if (code === KEYS.Back.code || code === KEYS.Backspace.code) { return accum; } code && accum.push(code); return accum; }, []); // we call them codes, they call them names tizen.tvinputdevice.registerKeyBatch(codes); }