Skip to content

Commit

Permalink
fix: add _ScrollViewComponent prop
Browse files Browse the repository at this point in the history
  • Loading branch information
1uokun committed Mar 15, 2024
1 parent 2a63ff4 commit ee8eb9a
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 39 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ toc: false

---

### 5.1.1
`2024-03-15`
- **PickerView** & **DatePickerView** & **Carousel**
- fix: remove import `react-native-gesture-handler/ScrollView`
- Let the user decide whether to use by `_ScrollViewComponent` prop

### 5.1.0
`2024-02-20`
- Refactor **Picker** & **PickerView**
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ toc: false

---

### 5.1.1
`2024-03-15`
- **PickerView** & **DatePickerView** & **Carousel**
- fix: 移除 `react-native-gesture-handler/ScrollView` 引用
- 提供 `_ScrollViewComponent` 属性让用户决定是否使用

### 5.1.0
`2024-02-23`
- 重构 **Picker** & **PickerView**
Expand Down
9 changes: 7 additions & 2 deletions components/carousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export interface CarouselPropsType
autoplay?: boolean
autoplayInterval?: number
infinite?: boolean
/**
* @description To fix: Carousel not scrolling in Android ScrollView
*/
_ScrollViewComponent?: any
}

export interface CarouselProps extends CarouselPropsType {
Expand Down Expand Up @@ -459,8 +463,9 @@ class Carousel extends React.PureComponent<CarouselProps, CarouselState> {
}

private renderScroll = (pages: React.ReactNode) => {
const ScrollViewComponent = this.props._ScrollViewComponent || ScrollView
return (
<ScrollView
<ScrollViewComponent
{...this.props}
horizontal={!this.props.vertical}
ref={this.scrollview as any}
Expand All @@ -483,7 +488,7 @@ class Carousel extends React.PureComponent<CarouselProps, CarouselState> {
}
: {})}>
{pages}
</ScrollView>
</ScrollViewComponent>
)
}

Expand Down
2 changes: 1 addition & 1 deletion components/date-picker-view/PropsType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface DatePickerViewPropsType
| 'numberOfLines'
| 'renderMaskTop'
| 'renderMaskBottom'
| 'withWrapper'
| '_ScrollViewComponent'
> {
value?: PickerDate
defaultValue?: PickerDate
Expand Down
9 changes: 2 additions & 7 deletions components/date-picker-view/demo/basic.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react'
import { ScrollView, Text } from 'react-native'
import { createNativeWrapper } from 'react-native-gesture-handler'
import { ScrollView as GestureScrollView } from 'react-native-gesture-handler'
import { DatePickerView } from '../../'
import { DatePickerFilter } from '../../date-picker/date-picker-utils'

Expand Down Expand Up @@ -40,12 +40,7 @@ export default () => {
precision="hour"
renderLabel={labelRenderer}
filter={dateFilter}
withWrapper={(Component) =>
createNativeWrapper(Component, {
disallowInterruption: true,
shouldCancelWhenOutside: false,
})
}
_ScrollViewComponent={GestureScrollView}
/>
</ScrollView>
)
Expand Down
16 changes: 1 addition & 15 deletions components/picker-view/PropsType.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { ReactNode } from 'react'
import { ComponentType } from 'react'
import { StyleProp, TextStyle, ViewStyle } from 'react-native'

export type PickerValue = string | number
Expand Down Expand Up @@ -35,18 +34,5 @@ export interface PickerViewPropsType {
renderLabel?: (item: PickerColumnItem, index: number) => ReactNode
renderMaskTop?: () => ReactNode
renderMaskBottom?: () => ReactNode
/**
* @description HOC for Wheel
* @example ```tsx
* import { createNativeWrapper } from 'react-native-gesture-handler'
*
* withWrapper={(Component) =>
* createNativeWrapper(Component, {
* disallowInterruption: true,
* shouldCancelWhenOutside: false,
* })
* }
* ```
*/
withWrapper?: (Component: ComponentType<any>) => ComponentType<any>
_ScrollViewComponent?: any
}
8 changes: 5 additions & 3 deletions components/picker-view/Wheel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Props = {
renderLabel: (item: ColumnItem, index: number) => ReactNode
itemHeight: number
wheelHeight: number
_ScrollViewComponent?: any
}

class Wheel extends React.Component<Props> {
Expand Down Expand Up @@ -167,11 +168,12 @@ class Wheel extends React.Component<Props> {
}

render() {
const ScrollViewComponent = this.props._ScrollViewComponent || ScrollView
return (
<ScrollView
<ScrollViewComponent
style={{ flex: 1 }}
horizontal={false}
ref={(el) => (this.scrollerRef = el)}
ref={(el: any) => (this.scrollerRef = el)}
showsHorizontalScrollIndicator={false}
showsVerticalScrollIndicator={false}
pagingEnabled={false}
Expand All @@ -191,7 +193,7 @@ class Wheel extends React.Component<Props> {
onMomentumScrollEnd: this.onMomentumScrollEnd,
})}>
{this.renderItems()}
</ScrollView>
</ScrollViewComponent>
)
}
}
Expand Down
9 changes: 2 additions & 7 deletions components/picker-view/demo/basic.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { ScrollView, Text } from 'react-native'
import { createNativeWrapper } from 'react-native-gesture-handler'
import { ScrollView as GestureScrollView } from 'react-native-gesture-handler'
import { PickerView } from '../../'

const basicColumns = [
Expand Down Expand Up @@ -42,12 +42,7 @@ export default class PickerViewExample extends React.Component {
padding: 0,
}}
// To fix: Wheel not scrolling in Android ScrollView
withWrapper={(Component) =>
createNativeWrapper(Component, {
disallowInterruption: true,
shouldCancelWhenOutside: false,
})
}
_ScrollViewComponent={GestureScrollView}
/>

<Text style={{ margin: 16 }}>受控模式</Text>
Expand Down
7 changes: 3 additions & 4 deletions components/picker-view/picker-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export default class RMCPickerView extends React.Component<
renderMaskBottom: () => (
<View style={{ flex: 1, backgroundColor: 'rgba(255,255,255,0.8)' }} />
),
withWrapper: (Component: any) => Component,
}

constructor(props: RMCPickerViewProps) {
Expand Down Expand Up @@ -111,10 +110,9 @@ export default class RMCPickerView extends React.Component<
numberOfLines,
handleSelect,
loadingContent,
withWrapper,
_ScrollViewComponent,
} = this.props
const itemHeight = this.props.itemHeight || this.state.itemHeight
const WheelHOC = withWrapper?.(Wheel) || Wheel
return (
<WithTheme themeStyles={pickerViewStyles} styles={styles}>
{(s) =>
Expand Down Expand Up @@ -146,7 +144,7 @@ export default class RMCPickerView extends React.Component<
: itemHeight > 0 &&
wheelHeight > 0 &&
columns.map((column, index) => (
<WheelHOC
<Wheel
key={index}
index={index}
column={column}
Expand All @@ -155,6 +153,7 @@ export default class RMCPickerView extends React.Component<
itemHeight={itemHeight}
wheelHeight={wheelHeight}
renderLabel={this.renderLabel}
_ScrollViewComponent={_ScrollViewComponent}
/>
))}
</View>
Expand Down

0 comments on commit ee8eb9a

Please sign in to comment.