Skip to content

Commit a13bd58

Browse files
committed
contentSytle关闭minHeight:100%的默认样式
1 parent b39efb7 commit a13bd58

4 files changed

Lines changed: 50 additions & 23 deletions

File tree

Examples/InputExample.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class InputExample extends React.Component {
2727
style={styles.input}
2828
placeholder="Keyboard Test Top"
2929
/>
30-
<Text style={[styles.text, styles.input]}>
30+
<Text style={styles.text}>
3131
Keyboard will never cover the focused TextInput
3232
</Text>
3333
<TextInput
@@ -50,7 +50,7 @@ const styles = StyleSheet.create({
5050
},
5151
text: {
5252
marginHorizontal: 20,
53-
marginVertical: 100,
53+
marginVertical: 300,
5454
fontSize: 30
5555
}
5656
});

Examples/RefreshAndLoadingExample.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { CommonLottieFooter } from "../src/Customize/CommonLottieFooter";
2323

2424
export class RefreshAndLoadingExample extends React.Component {
2525
_scrollView;
26-
_step = 12;
26+
_step = 13;
2727

2828
constructor(props) {
2929
super(props);
@@ -43,7 +43,7 @@ export class RefreshAndLoadingExample extends React.Component {
4343
inverted
4444
onRefresh={this._onRefresh}
4545
onLoading={this._onLoading}
46-
allLoaded={this.state.allLoaded}
46+
// allLoaded={this.state.allLoaded}
4747
refreshHeader={CommonLottieHeader}
4848
loadingFooter={CommonLottieFooter}
4949
>

src/SpringScrollView.js

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
9696
refreshHeader: Refresh,
9797
loadingFooter: Loading
9898
} = this.props;
99-
const wStyle = StyleSheet.flatten([styles.wrapperStyle, style, { transform: inverted ? [{ scaleY: -1 }] : [] }]);
99+
const wStyle = StyleSheet.flatten([
100+
styles.wrapperStyle,
101+
style,
102+
{ transform: inverted ? [{ scaleY: -1 }] : [] }
103+
]);
100104
const elements = (
101105
<SpringScrollViewNative
102106
{...this.props}
@@ -113,7 +117,7 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
113117
onNativeContentOffsetExtract={this._nativeOffset}
114118
>
115119
<SpringScrollContentViewNative
116-
style={StyleSheet.flatten([{ minHeight: "100%" }, this.props.contentStyle])}
120+
style={this.props.contentStyle}
117121
collapsable={false}
118122
onLayout={this._onContentLayoutChange}
119123
>
@@ -146,7 +150,11 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
146150
return (
147151
onRefresh && (
148152
<Animated.View style={this._getRefreshHeaderStyle()}>
149-
<Refresh ref={ref => (this._refreshHeader = ref)} offset={this._offsetY} maxHeight={Refresh.height} />
153+
<Refresh
154+
ref={ref => (this._refreshHeader = ref)}
155+
offset={this._offsetY}
156+
maxHeight={Refresh.height}
157+
/>
150158
</Animated.View>
151159
)
152160
);
@@ -177,7 +185,9 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
177185
if (!measured) return null;
178186
return (
179187
showsVerticalScrollIndicator &&
180-
this._contentHeight > this._height && <Animated.View style={this._getVerticalIndicatorStyle()} />
188+
this._contentHeight > this._height && (
189+
<Animated.View style={this._getVerticalIndicatorStyle()} />
190+
)
181191
);
182192
}
183193

@@ -188,7 +198,9 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
188198
if (!measured) return null;
189199
return (
190200
showsHorizontalScrollIndicator &&
191-
this._contentWidth > this._width && <Animated.View style={this._getHorizontalIndicatorStyle()} />
201+
this._contentWidth > this._width && (
202+
<Animated.View style={this._getHorizontalIndicatorStyle()} />
203+
)
192204
);
193205
}
194206

@@ -215,9 +227,18 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
215227

216228
scrollTo(offset: Offset, animated: boolean = true) {
217229
if (Platform.OS === "ios") {
218-
NativeModules.SpringScrollView.scrollTo(findNodeHandle(this._scrollView), offset.x, offset.y, animated);
230+
NativeModules.SpringScrollView.scrollTo(
231+
findNodeHandle(this._scrollView),
232+
offset.x,
233+
offset.y,
234+
animated
235+
);
219236
} else if (Platform.OS === "android") {
220-
UIManager.dispatchViewManagerCommand(findNodeHandle(this._scrollView), 10002, [offset.x, offset.y, animated]);
237+
UIManager.dispatchViewManagerCommand(findNodeHandle(this._scrollView), 10002, [
238+
offset.x,
239+
offset.y,
240+
animated
241+
]);
221242
}
222243
return new Promise((resolve, reject) => {
223244
if (animated) setTimeout(resolve, 500);
@@ -317,7 +338,7 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
317338
}
318339

319340
_getVerticalIndicatorStyle() {
320-
const indicatorHeight = (this._height / this._contentHeight) * this._height;
341+
const indicatorHeight = this._height / this._contentHeight * this._height;
321342
return {
322343
position: "absolute",
323344
top: 0,
@@ -336,7 +357,7 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
336357
}
337358

338359
_getHorizontalIndicatorStyle() {
339-
const indicatorWidth = (this._width / this._contentWidth) * this._width;
360+
const indicatorWidth = this._width / this._contentWidth * this._width;
340361
return {
341362
position: "absolute",
342363
bottom: 2,
@@ -380,7 +401,8 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
380401
console.warn(
381402
"unsupported value: '",
382403
style,
383-
"' in SpringScrollView, " + "select one in 'topping','stickyScrollView','stickyContent' please"
404+
"' in SpringScrollView, " +
405+
"select one in 'topping','stickyScrollView','stickyContent' please"
384406
);
385407
}
386408
if (this.props.inverted) transform.push({ scaleY: -1 });
@@ -421,14 +443,15 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
421443
console.warn(
422444
"unsupported value: '",
423445
style,
424-
"' in SpringScrollView, " + "select one in 'bottoming','stickyScrollView','stickyContent' please"
446+
"' in SpringScrollView, " +
447+
"select one in 'bottoming','stickyScrollView','stickyContent' please"
425448
);
426449
}
427450
if (this.props.inverted) transform.push({ scaleY: -1 });
428451
return {
429452
position: "absolute",
430453
right: 0,
431-
bottom: -fHeight,
454+
top: this._height > this._contentHeight ? this._height : this._contentHeight,
432455
height: fHeight,
433456
left: 0,
434457
transform
@@ -445,6 +468,7 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
445468
this._height = height;
446469
this._width = width;
447470
if (!this._contentHeight) return;
471+
if (this._contentHeight < this._height) this._contentHeight = height;
448472
if (this._offsetYValue > this._contentHeight - this._height) this.scrollToEnd();
449473
this.forceUpdate();
450474
}
@@ -460,13 +484,15 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
460484
this._contentHeight = height;
461485
this._contentWidth = width;
462486
if (!this._height) return;
487+
if (this._contentHeight < this._height) this._contentHeight = this._height;
463488
if (this._offsetYValue > this._contentHeight - this._height) this.scrollToEnd(false);
464489
this.forceUpdate();
465490
}
466491
};
467492

468493
_onTouchBegin = () => {
469-
if (TextInputState.currentlyFocusedField()) TextInputState.blurTextInput(TextInputState.currentlyFocusedField());
494+
if (TextInputState.currentlyFocusedField())
495+
TextInputState.blurTextInput(TextInputState.currentlyFocusedField());
470496
this._indicatorAnimation && this._indicatorAnimation.stop();
471497
this._indicatorOpacity.setValue(1);
472498
this.props.tapToHideKeyboard && Keyboard.dismiss();
@@ -499,4 +525,5 @@ const SpringScrollViewNative = Animated.createAnimatedComponent(
499525
requireNativeComponent("SpringScrollView", SpringScrollView)
500526
);
501527

502-
const SpringScrollContentViewNative = Platform.OS === "ios" ? requireNativeComponent("SpringScrollContentView") : View;
528+
const SpringScrollContentViewNative =
529+
Platform.OS === "ios" ? requireNativeComponent("SpringScrollContentView") : View;

src/ios/SpringScrollView/STSpringScrollView.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL
5858
} else if ([self shouldLoad]) {
5959
self.loadingStatus = @"loading";
6060
self.orgInsets = self.scrollView.contentInset;
61-
[self.scrollView setContentInset:UIEdgeInsetsMake(self.orgInsets.top, self.orgInsets.left, self.orgInsets.bottom+self.loadingFooterHeight, self.orgInsets.right)];
61+
CGFloat fill = .0f;
62+
if(self.scrollView.frame.size.height>self.scrollView.contentSize.height){
63+
fill=self.scrollView.frame.size.height-self.scrollView.contentSize.height;
64+
}
65+
[self.scrollView setContentInset:UIEdgeInsetsMake(self.orgInsets.top, self.orgInsets.left, self.orgInsets.bottom+self.loadingFooterHeight+fill, self.orgInsets.right)];
6266
}
6367
}
6468

@@ -87,7 +91,6 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
8791
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{
8892
if (!UIEdgeInsetsEqualToEdgeInsets(scrollView.contentInset, self.orgInsets) && ([self hitRefreshStatus:@[@"waiting"]] || [self hitLoadingStatus:@[@"waiting"]])) {
8993
scrollView.contentInset = self.orgInsets;
90-
// scrollView.scrollEnabled = self.orgScrollEnabled;
9194
}
9295
}
9396

@@ -96,16 +99,13 @@ - (void)endRefresh {
9699
self.refreshStatus = @"rebound";
97100
[self.scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
98101
self.orgScrollEnabled = self.scrollView.scrollEnabled;
99-
// self.scrollView.scrollEnabled = NO;
100102
}
101103
}
102104

103105
- (void)endLoading {
104106
if ([self hitLoadingStatus:@[@"loading"]]) {
105107
self.loadingStatus = @"rebound";
106108
[self.scrollView setContentOffset:CGPointMake(0, self.scrollView.contentSize.height-self.bounds.size.height) animated:YES];
107-
// self.orgScrollEnabled = self.scrollView.scrollEnabled;
108-
// self.scrollView.scrollEnabled = NO;
109109
}
110110
}
111111

0 commit comments

Comments
 (0)