Skip to content

Calculating parallaxHeaderHeight #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions examples/ListView/index.ios.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React from 'react'
import { AppRegistry, StatusBarIOS, processColor } from 'react-native';
import { AppRegistry, processColor } from 'react-native';

import Talks from './Talks';

StatusBarIOS.setStyle('light-content');

AppRegistry.registerComponent('ListViewExample', () => Talks);
10 changes: 8 additions & 2 deletions examples/ListView/ios/ListView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,10 @@
);
INFOPLIST_FILE = ListView/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
OTHER_LDFLAGS = "-ObjC";
OTHER_LDFLAGS = (
"-ObjC",
"-lc++",
);
PRODUCT_NAME = ListView;
};
name = Debug;
Expand All @@ -533,7 +536,10 @@
);
INFOPLIST_FILE = ListView/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
OTHER_LDFLAGS = "-ObjC";
OTHER_LDFLAGS = (
"-ObjC",
"-lc++",
);
PRODUCT_NAME = ListView;
};
name = Release;
Expand Down
4 changes: 2 additions & 2 deletions examples/ListView/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"start": "react-native start"
},
"dependencies": {
"react": "15.1.0",
"react-native": "0.27.2",
"react": "15.3.2",
"react-native": "0.37.0",
"react-native-parallax-scroll-view": "../../"
}
}
159 changes: 140 additions & 19 deletions examples/NestedViews/ios/NestedViews.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0620"
LastUpgradeVersion = "0810"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -37,10 +37,10 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -62,15 +62,18 @@
ReferencedContainer = "container:NestedViews.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand All @@ -86,10 +89,10 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand Down
17 changes: 8 additions & 9 deletions examples/NestedViews/ios/NestedViews/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand All @@ -22,6 +22,13 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
Expand All @@ -36,13 +43,5 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>NSAppTransportSecurity</key>
<dict>
<!--See http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/ -->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</plist>
2 changes: 1 addition & 1 deletion examples/NestedViews/ios/NestedViewsTests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
4 changes: 2 additions & 2 deletions examples/NestedViews/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"start": "react-native start"
},
"dependencies": {
"react": "15.1.0",
"react-native": "0.27.2",
"react": "15.3.2",
"react-native": "0.37.0",
"react-native-parallax-scroll-view": "../../"
}
}
31 changes: 16 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const IPropTypes = {
fadeOutBackground: bool,
contentBackgroundColor: string,
onChangeHeaderVisibility: func,
parallaxHeaderHeight: number.isRequired,
renderBackground: func,
renderFixedHeader: func,
renderForeground: func,
Expand All @@ -46,6 +45,7 @@ const IPropTypes = {
};

class ParallaxScrollView extends Component {

constructor(props) {
super(props);
if (props.renderStickyHeader && !props.stickyHeaderHeight) {
Expand All @@ -57,7 +57,8 @@ class ParallaxScrollView extends Component {
this.state = {
scrollY: new Animated.Value(0),
viewHeight: window.height,
viewWidth: window.width
viewWidth: window.width,
parallaxHeaderHeight: window.height
};
this._footerComponent = { setNativeProps() {} }; // Initial stub
this._footerHeight = 0;
Expand All @@ -71,7 +72,6 @@ class ParallaxScrollView extends Component {
contentBackgroundColor,
fadeOutForeground,
fadeOutBackground,
parallaxHeaderHeight,
renderBackground,
renderFixedHeader,
renderForeground,
Expand All @@ -84,11 +84,11 @@ class ParallaxScrollView extends Component {
...scrollViewProps
} = this.props;

const background = this._renderBackground({ fadeOutBackground, backgroundScrollSpeed, backgroundColor, parallaxHeaderHeight, stickyHeaderHeight, renderBackground });
const foreground = this._renderForeground({ fadeOutForeground, parallaxHeaderHeight, stickyHeaderHeight, renderForeground: renderForeground || renderParallaxHeader });
const background = this._renderBackground({ fadeOutBackground, backgroundScrollSpeed, backgroundColor, parallaxHeaderHeight: this.state.parallaxHeaderHeight, stickyHeaderHeight, renderBackground });
const foreground = this._renderForeground({ fadeOutForeground, parallaxHeaderHeight: this.state.parallaxHeaderHeight, stickyHeaderHeight, renderForeground: renderForeground || renderParallaxHeader });
const bodyComponent = this._wrapChildren(children, { contentBackgroundColor, stickyHeaderHeight, contentContainerStyle });
const footerSpacer = this._renderFooterSpacer({ contentBackgroundColor });
const maybeStickyHeader = this._maybeRenderStickyHeader({ parallaxHeaderHeight, stickyHeaderHeight, backgroundColor, renderFixedHeader, renderStickyHeader });
const maybeStickyHeader = this._maybeRenderStickyHeader({ parallaxHeaderHeight: this.state.parallaxHeaderHeight, stickyHeaderHeight, backgroundColor, renderFixedHeader, renderStickyHeader });
const scrollElement = renderScrollComponent(scrollViewProps);

return (
Expand Down Expand Up @@ -137,13 +137,12 @@ class ParallaxScrollView extends Component {

_onScroll(e) {
const {
parallaxHeaderHeight,
stickyHeaderHeight,
onChangeHeaderVisibility,
onScroll: prevOnScroll = () => {}
} = this.props;

const p = pivotPoint(parallaxHeaderHeight, stickyHeaderHeight);
const p = pivotPoint(this.state.parallaxHeaderHeight, stickyHeaderHeight);

this._maybeUpdateScrollPosition(e);

Expand All @@ -159,10 +158,10 @@ class ParallaxScrollView extends Component {
// This optimizes the state update of current scrollY since we don't need to
// perform any updates when user has scrolled past the pivot point.
_maybeUpdateScrollPosition(e) {
const { parallaxHeaderHeight, stickyHeaderHeight } = this.props;
const { stickyHeaderHeight } = this.props;
const { scrollY } = this.state;
const { nativeEvent: { contentOffset: { y: offsetY } } } = e;
const p = pivotPoint(parallaxHeaderHeight, stickyHeaderHeight);
const p = pivotPoint(this.state.parallaxHeaderHeight, stickyHeaderHeight);

if (offsetY <= p || scrollY._value <= p) {
scrollY.setValue(offsetY);
Expand Down Expand Up @@ -220,12 +219,16 @@ class ParallaxScrollView extends Component {

_renderForeground({ fadeOutForeground, parallaxHeaderHeight, stickyHeaderHeight, renderForeground }) {
const { scrollY } = this.state;
const _this = this;
const p = pivotPoint(parallaxHeaderHeight, stickyHeaderHeight);
return (
<View style={styles.parallaxHeaderContainer}>
<View style={styles.parallaxHeaderContainer}
onLayout={e => {
const { x, y, width, height } = e.nativeEvent.layout;
_this.setState({parallaxHeaderHeight: height});
}}>
<Animated.View
style={[styles.parallaxHeader, {
height: parallaxHeaderHeight,
opacity: fadeOutForeground
? interpolate(scrollY, {
inputRange: [0, p * (1/2), p * (3/4), p],
Expand All @@ -234,9 +237,7 @@ class ParallaxScrollView extends Component {
})
: 1
}]}>
<View style={{ height: parallaxHeaderHeight }}>
{ renderForeground() }
</View>
{ renderForeground() }
</Animated.View>
</View>
);
Expand Down