목차
TVFocusGuideView를 사용하면 TVFocusGuideView의 '대상'으로 등록할 구성 요소 배열을 설정할 수 있습니다. 예시를 살펴보겠습니다.
이 소품은 주어진 방향에 대해 포커스가 상위 구성 요소에서 벗어나지 않도록 보장합니다. 이 소품은 주어진 방향에 대해 포커스가 상위 구성 요소에서 벗어나지 않도록 보장합니다. 예시를 살펴보겠습니다.
자동 초점이 true로 설정되면 TVFocusGuideView가 초점을 맞출 수 있는 첫 번째 하위 항목으로 초점을 리디렉션하여 초점을 관리합니다. 또한 마지막으로 초점을 맞춘 어린이를 기억하고 후속 방문 시 해당 어린이에게 초점을 리디렉션합니다. 이 prop을 Destinations Prop과 함께 사용하면 Destinations Prop에 의해 설정된 구성 요소가 우선 적용됩니다. 예시를 살펴보겠습니다.
웹 프론트엔드 JS 튜토리얼 React Native에서 초점을 관리하는 방법

React Native에서 초점을 관리하는 방법

Sep 12, 2024 am 10:31 AM

TV용 React Native 앱에서 포커스 관리를 처리할 때 개발자는 다음과 같은 5가지 익숙한 단계(슬픔)를 겪게 될 수 있습니다. ? ? ? ?

포커스 관리는 다양한 포커스 관리 기술로 이어진 TV 플랫폼 간의 단편화로 인해 TV 애플리케이션 개발에서 독특한 과제입니다. 개발자는 포커스 관리를 위한 여러 전략을 만들고 채택해야 했으며 종종 플랫폼 간 추상화와 함께 플랫폼별 솔루션을 저글링해야 했습니다. 포커스의 과제는 포커스가 올바르게 처리되도록 보장하는 것뿐만 아니라 플랫폼 차이를 처리하는 것입니다. Android TV와 Apple의 tvOS에는 고유한 네이티브 포커스 엔진이 있습니다. 이에 대한 자세한 내용은 제 동료 @hellonehha가 작성한 이 기사에서 읽어보실 수 있습니다.

ays Of Managing Focus In React Native

원래 TV 관련 문서와 API는 기본 React Native 문서의 일부였습니다. 이제 대부분의 TV 관련 콘텐츠가 React-native-tvos 프로젝트로 이동되었습니다.

ays Of Managing Focus In React Native

반응 네이티브 TVOS

"react-native": "npm:react-native-tvos@latest"

react-native-tvos 프로젝트는 Apple TV 및 Android TV 플랫폼 지원에 특히 중점을 두고 핵심 React Native 프레임워크에 대한 추가 기능과 확장 기능을 제공하는 오픈 소스 패키지입니다. 이 프로젝트의 변경 사항 대부분은 리모컨의 D패드를 사용하여 SmartTV에서 포커스 기반 탐색을 처리하는 데 중점을 두고 있습니다. 이 프로젝트는 (놀라운!) Doug Lowder에 의해 유지 관리되며 일반적으로 React Native TV 애플리케이션에서 포커스 관리를 처리하는 기본 방법으로 권장됩니다.

그러나 커뮤니티에서 유지 관리하는 많은 프로젝트와 마찬가지로 React-native-tvos 프로젝트는 개발자의 요구에 따라 발전해 왔으며 이제 포커스를 처리하는 여러 가지 방법이 있습니다. React-native-tvos가 제공하는 기존 구성 요소에 대한 추가 구성 요소와 향상된 기능을 살펴보겠습니다.

1. TV포커스가이드뷰

예를 들어 TVFocusGuideView 구성 요소 내부에 렌더링된 10개의 Pressable 구성 요소로 구성된 그리드는 다음과 같습니다.


import { TVFocusGuideView } from 'react-native';

const TVFocusGuideViewExample = () => {
  const [focusedItem, setFocusedItem] = useState(null);

  const renderGridItem = number => (
    <Pressable
      style={[styles.gridItem, focusedItem === number && styles.focusedItem]}
      key={number}
      onFocus={() => setFocusedItem(number)}
      onBlur={() => setFocusedItem(null)}>
      <Text style={styles.gridItemText}>{number}</Text>
    </Pressable>
  );

  return (
    <>
      <Header headerText="Movies" />
      <TVFocusGuideView trapFocusLeft style={styles.grid}>
        {[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(num => renderGridItem(num))}
      </TVFocusGuideView>
    </>
  );
};
로그인 후 복사

TVFocusGuideView는 포커스를 처리하는 데 도움이 되는 몇 가지 소품을 허용합니다.ays Of Managing Focus In React Native

목적지 소품

TVFocusGuideView를 사용하면 TVFocusGuideView의 '대상'으로 등록할 구성 요소 배열을 설정할 수 있습니다. 예시를 살펴보겠습니다.

<TVFocusGuideView destinations={[]}>
로그인 후 복사

목적지 소품을 항목 8(destinations={[item8Ref.current]})에 대한 참조로 설정하면 TVFocusGuideView를 처음 탐색할 때 초점이 항목 8로 이동합니다.

TrapFocus 소품 ays Of Managing Focus In React Native

이 소품은 주어진 방향에 대해 포커스가 상위 구성 요소에서 벗어나지 않도록 보장합니다. 이 소품은 주어진 방향에 대해 포커스가 상위 구성 요소에서 벗어나지 않도록 보장합니다. 예시를 살펴보겠습니다.

<TVFocusGuideView trapFocusUp|trapFocusDown|trapFocusLeft|trapFocusRight  />
로그인 후 복사

trapFocusLeft 소품을 사용하면 더 이상 컨테이너 외부에서 왼쪽으로 탐색할 수 없습니다.

자동 초점 소품 ays Of Managing Focus In React Native

자동 초점이 true로 설정되면 TVFocusGuideView가 초점을 맞출 수 있는 첫 번째 하위 항목으로 초점을 리디렉션하여 초점을 관리합니다. 또한 마지막으로 초점을 맞춘 어린이를 기억하고 후속 방문 시 해당 어린이에게 초점을 리디렉션합니다. 이 prop을 Destinations Prop과 함께 사용하면 Destinations Prop에 의해 설정된 구성 요소가 우선 적용됩니다. 예시를 살펴보겠습니다.

 <TVFocusGuideView autoFocus />
로그인 후 복사

이 소품이 없으면 Header 구성 요소에서 TVFocusGuideView 포커스로 가장 가까운 구성 요소로 이동할 때 항목 3(Android 근접 기반 내장 포커스 엔진에 따라)

    자동 초점 소품을 사용하면 항목 1로 이동합니다

2. Touchable

With the react-native-tvos, the Touchable component's ( TouchableWithoutFeedback, TouchableHighlight and TouchableOpacity) include additional code to detect focus changes and properly style the components when focused. It also ensures that the appropriate actions are triggered when the user interacts with the Touchable views using the TV remote control.

Specifically, the onFocus event is fired when the Touchable view gains focus, and the onBlur event is fired when the view loses focus. This enables you to apply unique styling or logic when the component is in the focused state that doesn’t come out of the box with core React Native.

Additionally the onPress method has been modified to be triggered when the user selects the Touchable by pressing the "select" button on the TV remote (the center button on the Apple TV remote or the center button on the Android TV D-Pad) and the onLongPress event is executed twice when the "select" button is held down for a certain duration.

3. Pressable

Like Touchable, the Pressable component been enhanced to allow it to accept the onFocus and onBlur props.
Similar to the ‘pressed’ state that is triggered when a user presses the component on a touchscreen, the react-native-tvos Pressable component introduces a focused state that becomes true when the component is focused on the TV screen.

Here’s an example when using the Pressable and Touchable components from React Native core and they do not accept / execute the onFocus and onBlur props:

ays Of Managing Focus In React Native

Using the same Pressable and Touchable components from react-native-tvos they accept and execute the onFocus and onBlur props:

ays Of Managing Focus In React Native

4. hasTVPreferredFocus prop

Some React Native components have the hasTVPreferredFocus prop, which helps you prioritise focus. If set to true, hasTVPreferredFocus will force the focus to that element. According to the React Native docs these are the current components that accept the prop:

ays Of Managing Focus In React Native

However, if you are using react-native-tvOS, there are a lot more components that accept this prop:

<View hasTVPreferredFocus />
<Pressable hasTVPreferredFocus />
<TouchableHighlight hasTVPreferredFocus />
<TouchableOpacity hasTVPreferredFocus />
<TextInput hasTVPreferredFocus />
<Button hasTVPreferredFocus />
<TVFocusGuideView hasTVPreferredFocus />
<TouchableNativeFeedback hasTVPreferredFocus />
<TVTextScrollView hasTVPreferredFocus />
<TouchableWithoutFeedback hasTVPreferredFocus />
로그인 후 복사

Lets look at an example:

  • Setting the hasTVPreferredFocus prop to true for Pressable 2 causes focus be on Pressable 2
  • Changing it to be true when we are on Pressable 3 causes focus to move to Pressable 3

ays Of Managing Focus In React Native

5. nextFocusDirection prop

The nextFocusDirection prop designates the next Component to receive focus when the user navigates in the specified direction helping you handle focus navigation. When using react-native-tvos, this prop is accepted by the same components that accept the hasTVPreferredFocus prop (View, TouchableHighlight, Pressable, TouchableOpacity, TextInput, TVFocusGuideView, TouchableNativeFeedback, Button). Lets look at an example:

nextFocusDown={pressableRef3.current}
nextFocusRight={pressableRef5.current}>
로그인 후 복사
  • Setting the nextFocusDown prop to Pressable 3 causes focus to move to Pressable 3 when the focus moves down
  • Setting the nextFocusRight prop to Pressable 5 causes focus to move to Pressable 5 when the focus moves right

ays Of Managing Focus In React Native

Conclusion

When it comes to handling focus management, there is no one-size-fits-all solution for React Native TV apps. The approach ultimately depends on the specific needs and requirements of your project. While the react-native-tvos provides a useful cross-device abstractions, you may have to adopt platform-specific solutions to handle common fragmentation issues across SmartTV platforms.

Take the time to explore these various focus management solutions so that you can deliver an intuitive focus handling experience for your users, regardless of the SmartTV platform they are using.

Related resources

  • https://dev.to/amazonappdev/tv-navigation-in-react-native-a-guide-to-using-tvfocusguideview-302i
  • https://medium.com/xite-engineering/revolutionizing-focus-management-in-tv-applications-with-react-native-10ba69bd90
  • https://reactnative.dev/docs/0.72/building-for-tv

위 내용은 React Native에서 초점을 관리하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

<gum> : Bubble Gum Simulator Infinity- 로얄 키를 얻고 사용하는 방법
4 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
Nordhold : Fusion System, 설명
4 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
Mandragora : 마녀 트리의 속삭임 - Grappling Hook 잠금 해제 방법
3 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

Python vs. JavaScript : 학습 곡선 및 사용 편의성 Python vs. JavaScript : 학습 곡선 및 사용 편의성 Apr 16, 2025 am 12:12 AM

Python은 부드러운 학습 곡선과 간결한 구문으로 초보자에게 더 적합합니다. JavaScript는 가파른 학습 곡선과 유연한 구문으로 프론트 엔드 개발에 적합합니다. 1. Python Syntax는 직관적이며 데이터 과학 및 백엔드 개발에 적합합니다. 2. JavaScript는 유연하며 프론트 엔드 및 서버 측 프로그래밍에서 널리 사용됩니다.

JavaScript 및 웹 : 핵심 기능 및 사용 사례 JavaScript 및 웹 : 핵심 기능 및 사용 사례 Apr 18, 2025 am 12:19 AM

웹 개발에서 JavaScript의 주요 용도에는 클라이언트 상호 작용, 양식 검증 및 비동기 통신이 포함됩니다. 1) DOM 운영을 통한 동적 컨텐츠 업데이트 및 사용자 상호 작용; 2) 사용자가 사용자 경험을 향상시키기 위해 데이터를 제출하기 전에 클라이언트 확인이 수행됩니다. 3) 서버와의 진실한 통신은 Ajax 기술을 통해 달성됩니다.

자바 스크립트 행동 : 실제 예제 및 프로젝트 자바 스크립트 행동 : 실제 예제 및 프로젝트 Apr 19, 2025 am 12:13 AM

실제 세계에서 JavaScript의 응용 프로그램에는 프론트 엔드 및 백엔드 개발이 포함됩니다. 1) DOM 운영 및 이벤트 처리와 관련된 TODO 목록 응용 프로그램을 구축하여 프론트 엔드 애플리케이션을 표시합니다. 2) Node.js를 통해 RESTFULAPI를 구축하고 Express를 통해 백엔드 응용 프로그램을 시연하십시오.

JavaScript 엔진 이해 : 구현 세부 사항 JavaScript 엔진 이해 : 구현 세부 사항 Apr 17, 2025 am 12:05 AM

보다 효율적인 코드를 작성하고 성능 병목 현상 및 최적화 전략을 이해하는 데 도움이되기 때문에 JavaScript 엔진이 내부적으로 작동하는 방식을 이해하는 것은 개발자에게 중요합니다. 1) 엔진의 워크 플로에는 구문 분석, 컴파일 및 실행; 2) 실행 프로세스 중에 엔진은 인라인 캐시 및 숨겨진 클래스와 같은 동적 최적화를 수행합니다. 3) 모범 사례에는 글로벌 변수를 피하고 루프 최적화, Const 및 Lets 사용 및 과도한 폐쇄 사용을 피하는 것이 포함됩니다.

Python vs. JavaScript : 커뮤니티, 라이브러리 및 리소스 Python vs. JavaScript : 커뮤니티, 라이브러리 및 리소스 Apr 15, 2025 am 12:16 AM

Python과 JavaScript는 커뮤니티, 라이브러리 및 리소스 측면에서 고유 한 장점과 단점이 있습니다. 1) Python 커뮤니티는 친절하고 초보자에게 적합하지만 프론트 엔드 개발 리소스는 JavaScript만큼 풍부하지 않습니다. 2) Python은 데이터 과학 및 기계 학습 라이브러리에서 강력하며 JavaScript는 프론트 엔드 개발 라이브러리 및 프레임 워크에서 더 좋습니다. 3) 둘 다 풍부한 학습 리소스를 가지고 있지만 Python은 공식 문서로 시작하는 데 적합하지만 JavaScript는 MDNWebDocs에서 더 좋습니다. 선택은 프로젝트 요구와 개인적인 이익을 기반으로해야합니다.

Python vs. JavaScript : 개발 환경 및 도구 Python vs. JavaScript : 개발 환경 및 도구 Apr 26, 2025 am 12:09 AM

개발 환경에서 Python과 JavaScript의 선택이 모두 중요합니다. 1) Python의 개발 환경에는 Pycharm, Jupyternotebook 및 Anaconda가 포함되어 있으며 데이터 과학 및 빠른 프로토 타이핑에 적합합니다. 2) JavaScript의 개발 환경에는 Node.js, VScode 및 Webpack이 포함되어 있으며 프론트 엔드 및 백엔드 개발에 적합합니다. 프로젝트 요구에 따라 올바른 도구를 선택하면 개발 효율성과 프로젝트 성공률이 향상 될 수 있습니다.

JavaScript 통역사 및 컴파일러에서 C/C의 역할 JavaScript 통역사 및 컴파일러에서 C/C의 역할 Apr 20, 2025 am 12:01 AM

C와 C는 주로 통역사와 JIT 컴파일러를 구현하는 데 사용되는 JavaScript 엔진에서 중요한 역할을합니다. 1) C는 JavaScript 소스 코드를 구문 분석하고 추상 구문 트리를 생성하는 데 사용됩니다. 2) C는 바이트 코드 생성 및 실행을 담당합니다. 3) C는 JIT 컴파일러를 구현하고 런타임에 핫스팟 코드를 최적화하고 컴파일하며 JavaScript의 실행 효율을 크게 향상시킵니다.

Python vs. JavaScript : 사용 사례 및 응용 프로그램 비교 Python vs. JavaScript : 사용 사례 및 응용 프로그램 비교 Apr 21, 2025 am 12:01 AM

Python은 데이터 과학 및 자동화에 더 적합한 반면 JavaScript는 프론트 엔드 및 풀 스택 개발에 더 적합합니다. 1. Python은 데이터 처리 및 모델링을 위해 Numpy 및 Pandas와 같은 라이브러리를 사용하여 데이터 과학 및 기계 학습에서 잘 수행됩니다. 2. 파이썬은 간결하고 자동화 및 스크립팅이 효율적입니다. 3. JavaScript는 프론트 엔드 개발에 없어서는 안될 것이며 동적 웹 페이지 및 단일 페이지 응용 프로그램을 구축하는 데 사용됩니다. 4. JavaScript는 Node.js를 통해 백엔드 개발에 역할을하며 전체 스택 개발을 지원합니다.

See all articles