@@ -2,24 +2,21 @@ import {
22 type LightningElement ,
33 LightningViewElement ,
44 type LightningViewElementProps ,
5- simpleDiff ,
65} from '@plextv/react-lightning' ;
7- import { Component , createRef } from 'react' ;
6+ import { createRef , PureComponent } from 'react' ;
87import type { JSX } from 'react/jsx-runtime' ;
98import type {
109 NativeScrollEvent ,
1110 ScrollView as RNScrollView ,
1211 ScrollViewProps as RNScrollViewProps ,
1312} from 'react-native' ;
14- import { View } from 'react-native' ;
1513import type { LightningViewElementStyle } from '../../../react-lightning/src/types' ;
14+ import { createHandler } from '../hooks/useFocusHandler' ;
1615import { createNativeSyntheticEvent } from '../utils/createNativeSyntheticEvent' ;
17- import { FocusGroup } from './FocusGroup' ;
18- import { defaultViewStyle } from './View' ;
16+ import { defaultViewStyle , View } from './View' ;
1917
2018type ScrollViewProps = RNScrollViewProps & {
2119 animated ?: boolean ;
22- onChildFocused ?: ( el : LightningElement ) => void ;
2320} ;
2421
2522type ScrollViewState = {
@@ -108,7 +105,10 @@ function getScrollInfo(
108105 } ;
109106}
110107
111- export class ScrollView extends Component < ScrollViewProps , ScrollViewState > {
108+ export class ScrollView extends PureComponent <
109+ ScrollViewProps ,
110+ ScrollViewState
111+ > {
112112 private _containerRef = createRef < LightningViewElement > ( ) ;
113113 private _viewportRef = createRef < LightningViewElement > ( ) ;
114114
@@ -189,24 +189,9 @@ export class ScrollView extends Component<ScrollViewProps, ScrollViewState> {
189189 return this . _containerRef . current ;
190190 }
191191
192- public shouldComponentUpdate (
193- nextProps : ScrollViewProps ,
194- nextState : ScrollViewState ,
195- ) : boolean {
196- return (
197- ! ! simpleDiff ( this . props , nextProps ) || ! ! simpleDiff ( this . state , nextState )
198- ) ;
199- }
200-
201192 public render ( ) : JSX . Element {
202- const {
203- children,
204- style,
205- contentContainerStyle,
206- horizontal,
207- onChildFocused,
208- ...props
209- } = this . props ;
193+ const { children, style, contentContainerStyle, horizontal, ...props } =
194+ this . props ;
210195 const flexDirection = horizontal ? 'row' : 'column' ;
211196
212197 return (
@@ -218,8 +203,10 @@ export class ScrollView extends Component<ScrollViewProps, ScrollViewState> {
218203 { overflow : 'hidden' , flexDirection, flexGrow : 1 , flexShrink : 1 } ,
219204 ] }
220205 { ...props }
206+ onFocus = { createHandler ( this . props . onFocus ) }
207+ onBlur = { createHandler ( this . props . onBlur ) }
221208 >
222- < FocusGroup
209+ < View
223210 ref = { this . _containerRef }
224211 transition = {
225212 this . state . animated
@@ -229,7 +216,6 @@ export class ScrollView extends Component<ScrollViewProps, ScrollViewState> {
229216 }
230217 : undefined
231218 }
232- onChildFocused = { onChildFocused }
233219 style = { [
234220 defaultViewStyle ,
235221 { display : 'flex' , flexDirection } ,
@@ -238,7 +224,7 @@ export class ScrollView extends Component<ScrollViewProps, ScrollViewState> {
238224 ] }
239225 >
240226 { children }
241- </ FocusGroup >
227+ </ View >
242228 </ View >
243229 ) ;
244230 }
@@ -264,9 +250,7 @@ export class ScrollView extends Component<ScrollViewProps, ScrollViewState> {
264250 } ;
265251
266252 private _setViewRef = ( ref : View | null ) => {
267- this . _viewportRef . current = ref
268- ? ( ref as unknown as LightningViewElement )
269- : null ;
253+ this . _viewportRef . current = ref ?? null ;
270254 } ;
271255
272256 private _doScroll ( newOffset : NativeScrollEvent ) {
0 commit comments