Skip to content

Commit

Permalink
Merge pull request #670 from shoutem/release/4.7.0
Browse files Browse the repository at this point in the history
Release/4.7.0
  • Loading branch information
Definitely-Not-Vlad authored Jan 19, 2022
2 parents 1fd141e + cdbdff0 commit c4c3f4c
Show file tree
Hide file tree
Showing 8 changed files with 1,130 additions and 966 deletions.
24 changes: 22 additions & 2 deletions components/ScrollView/ScrollDriverProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export class ScrollDriverProvider extends PureComponent {
static propTypes = {
children: PropTypes.node,
driver: DriverShape,
// Used to propagate animation driver changes to components who aren't
// children of ScrollDriver, recieves driver as argument.
// TODO: Rewrite for new context API.
onAnimationDriverChange: PropTypes.func,
onScroll: PropTypes.func,
};

constructor(props, context) {
Expand All @@ -42,19 +47,34 @@ export class ScrollDriverProvider extends PureComponent {
}

setupAnimationDriver(props, context) {
const { onAnimationDriverChange } = this.props;

if (props.driver) {
this.animationDriver = props.driver;
} else if (context.driverProvider) {
this.animationDriver = context.animationDriver;
} else if (!this.animationDriver) {
this.animationDriver = new ScrollDriver({ useNativeDriver: true });
this.animationDriver = new ScrollDriver(
{ useNativeDriver: true, nativeScrollEventThrottle: 20 },
props.onScroll,
);
}

if (onAnimationDriverChange) {
onAnimationDriverChange(this.animationDriver);
}
}

setAnimationDriver(driver, primaryScrollView) {
if (driver || !this.animationDriver || primaryScrollView) {
_.assign(this.animationDriver, driver);
const { onAnimationDriverChange } = this.props;
const { driverProvider } = this.context;

_.assign(this.animationDriver, driver);
if (onAnimationDriverChange) {
onAnimationDriverChange(driver);
}

if (driverProvider) {
driverProvider.setAnimationDriver(driver, primaryScrollView);
}
Expand Down
12 changes: 7 additions & 5 deletions components/ScrollView/ScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const IPHONE_X_HOME_INDICATOR_PADDING = isTabBarOnScreen ? 0 : 34;
class ScrollView extends PureComponent {
static propTypes = {
...Animated.ScrollView.propTypes,
primary: PropTypes.bool,
};

static contextTypes = {
Expand All @@ -33,7 +34,11 @@ class ScrollView extends PureComponent {
autoBindReact(this);

this.animationDriver =
props.driver || new ScrollDriver({ useNativeDriver: true });
props.driver ||
new ScrollDriver(
{ useNativeDriver: true, nativeScrollEventThrottle: 20 },
props.onScroll,
);
}

getChildContext() {
Expand All @@ -53,12 +58,9 @@ class ScrollView extends PureComponent {

componentDidUpdate() {
const { driver } = this.props;
const { animationDriver } = this.context;

if (driver && this.animationDriver !== driver) {
this.animationDriver = driver;
} else if (animationDriver && this.animationDriver !== animationDriver) {
this.animationDriver = animationDriver;
}
}

Expand Down Expand Up @@ -92,7 +94,7 @@ class ScrollView extends PureComponent {
ref={this.setWrappedInstance}
contentContainerStyle={this.addIphoneXPadding(contentContainerStyle)}
{...animationDriver.scrollViewProps}
{...props}
{..._.omit(props, 'onScroll')}
/>
);
}
Expand Down
61 changes: 28 additions & 33 deletions examples/create-react-native-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions helpers/device-selector.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Platform, Dimensions } from 'react-native';
import { hasNotch } from 'react-native-device-info';
import _ from 'lodash';
import {
IPHONE_X_LONG_SIDE,
Expand Down Expand Up @@ -30,6 +31,8 @@ const isIphoneXR =
!isTVOS &&
(xrDimensionsMatch || twelveDimensionsMatch || twelveMaxDimensionsMatch);

const isNotchedAndroid = OS === 'android' && hasNotch();

/**
* Receives settings for different devices
* If the device is recognized, it returns only settings for that device
Expand All @@ -48,11 +51,16 @@ function select(settings) {
return settings.iPhoneXR;
}

if (settings.notchedAndroid && isNotchedAndroid) {
return settings.notchedAndroid;
}

return _.get(settings, 'default');
}

export const Device = {
isIphoneX,
isIphoneXR,
isNotchedAndroid,
select,
};
5 changes: 2 additions & 3 deletions helpers/keyboard.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Platform } from 'react-native';
import { getStatusBarHeight } from 'react-native-status-bar-height';
import { Platform, StatusBar } from 'react-native';
import { NAVIGATION_BAR_HEIGHT } from '../theme';

export function calculateKeyboardOffset(extraOffset = 0) {
Expand All @@ -9,7 +8,7 @@ export function calculateKeyboardOffset(extraOffset = 0) {
return resolvedOffset;
}

return getStatusBarHeight() + resolvedOffset;
return StatusBar.currentHeight + resolvedOffset;
}

export default { calculateKeyboardOffset };
Loading

0 comments on commit c4c3f4c

Please sign in to comment.