Skip to content
This repository has been archived by the owner on Nov 2, 2022. It is now read-only.

Commit

Permalink
feat: 新增 containerProps 属性
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicleo committed Dec 10, 2020
1 parent 093059b commit 06adca2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ module.exports = {
tabWidth: 2,
printWidth: 100,
singleQuote: true,
trailingComma: "all",
jsxSingleQuote: true
trailingComma: 'all',
jsxSingleQuote: true,
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"peerDependencies": {
"react": "^16.13.1",
"remax": ">=2.4.1"
"remax": "^2.10.1"
},
"devDependencies": {
"@commitlint/cli": "^8.1.0",
Expand Down
File renamed without changes.
8 changes: 7 additions & 1 deletion src/component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import React from 'react';
import { ScrollViewProps as AliScrollViewProps } from 'remax/ali';
import { View } from 'remax/one';
import { ScrollViewProps as ToutiaoScrollViewProps } from 'remax/toutiao';
import { ScrollViewProps as WechatScrollViewProps } from 'remax/wechat';

export const isNativePlatform = ['ali', 'wechat', 'toutiao'].includes(
process.env.REMAX_PLATFORM as string,
);

export type ScrollViewProps = AliScrollViewProps | WechatScrollViewProps | ToutiaoScrollViewProps;

export { View };

export const ScrollView: React.FC<any> = React.forwardRef((props, ref) => {
export const ScrollView: React.ForwardRefExoticComponent<any> = React.forwardRef((props, ref) => {
const { isGrid, layout, style, onScroll, ...rest } = props;

function handleScroll(event: any) {
if (typeof onScroll === 'function') {
const isHorizontal = layout === 'horizontal';
Expand Down
8 changes: 6 additions & 2 deletions src/createGridComponent.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import memoizeOne from 'memoize-one';
import { createElement, PureComponent } from 'react';
import { ScrollView, View } from './component';

import { ScrollView, ScrollViewProps, View } from './component';
import { getRTLOffsetType, getScrollbarSize } from './utils/domHelpers';
import { cancelTimeout, requestTimeout, TimeoutID } from './utils/timer';
import { getScrollbarSize, getRTLOffsetType } from './utils/domHelpers';

type Direction = 'ltr' | 'rtl';
export type ScrollToAlign = 'auto' | 'smart' | 'center' | 'start' | 'end';
Expand Down Expand Up @@ -107,6 +108,7 @@ export type Props<T> = {
style?: React.CSSProperties;
useIsScrolling: boolean;
width: number;
containerProps?: ScrollViewProps;
};

type State = {
Expand Down Expand Up @@ -361,6 +363,7 @@ export default function createGridComponent({
style,
useIsScrolling,
width,
containerProps = {},
} = this.props;
const { isScrolling } = this.state;
const [columnStartIndex, columnStopIndex] = this._getHorizontalRangeToRender();
Expand Down Expand Up @@ -389,6 +392,7 @@ export default function createGridComponent({
return createElement(
(outerElementType || outerTagName || ScrollView) as any,
{
...containerProps,
className,
onScroll: this._onScroll,
ref: this._outerRefSetter,
Expand Down
10 changes: 6 additions & 4 deletions src/createListComponent.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import memoizeOne from 'memoize-one';
import { createElement, PureComponent } from 'react';
import { ScrollView, View } from './component';
import { cancelTimeout, requestTimeout } from './utils/timer';
import { getRTLOffsetType } from './utils/domHelpers';

import { TimeoutID } from './utils/timer';
import { ScrollView, ScrollViewProps, View } from './component';
import { getRTLOffsetType } from './utils/domHelpers';
import { cancelTimeout, requestTimeout, TimeoutID } from './utils/timer';

export type ScrollToAlign = 'auto' | 'smart' | 'center' | 'start' | 'end';

Expand Down Expand Up @@ -91,6 +90,7 @@ export type Props<T> = {
style?: React.CSSProperties;
useIsScrolling: boolean;
width: number | string;
containerProps?: ScrollViewProps;
};

type State = {
Expand Down Expand Up @@ -272,6 +272,7 @@ export default function createListComponent({
style,
useIsScrolling,
width,
containerProps = {},
} = this.props;
const { isScrolling } = this.state;
const isHorizontal = layout === 'horizontal';
Expand All @@ -298,6 +299,7 @@ export default function createListComponent({
return createElement(
(outerElementType || outerTagName || ScrollView) as any,
{
...containerProps,
className,
onScroll,
ref: this._outerRefSetter,
Expand Down

0 comments on commit 06adca2

Please # to comment.