Skip to content
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

Add onInsetsChange property to SafeAreaView #19627

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2e75e28
Add onInsetsChange prop to SafeAreaView
clmntcrl Jun 8, 2018
982f893
Remove @providesModule
clmntcrl Jun 8, 2018
26a8d5c
Fix issues to pass Flow tests
clmntcrl Jun 8, 2018
1a557b7
Merge branch 'master' into components-safeareaview-oninsetschange
clmntcrl Jun 10, 2018
d957014
Merge branch 'master' into components-safeareaview-oninsetschange
clmntcrl Jun 11, 2018
58dc07a
Merge branch 'master' into components-safeareaview-oninsetschange
clmntcrl Jul 4, 2018
70c6055
Add onInsetsChange prop to SafeAreaView
clmntcrl Jun 8, 2018
758ae93
Remove @providesModule
clmntcrl Jun 8, 2018
59faec2
Fix issues to pass Flow tests
clmntcrl Jun 8, 2018
0d26336
Merge branch 'components-safeareaview-oninsetschange' of https://gith…
clmntcrl Aug 4, 2018
5dc2ff9
Merge branch 'master' into components-safeareaview-oninsetschange
clmntcrl Aug 6, 2018
35cbf1b
Merge branch 'components-safeareaview-oninsetschange' of https://gith…
clmntcrl Aug 6, 2018
c2d4cb6
Fix `children` is missing in props flow test error
clmntcrl Aug 7, 2018
48e697c
Merge branch 'master' into components-safeareaview-oninsetschange
clmntcrl Aug 7, 2018
ca61a6b
A better children PropType
clmntcrl Aug 10, 2018
d956812
Merge branch 'master' into components-safeareaview-oninsetschange
clmntcrl Aug 23, 2018
1a93364
Better Flow type for onInsetsChange
clmntcrl Aug 24, 2018
dc366ed
Merge branch 'master' into components-safeareaview-oninsetschange
clmntcrl Aug 24, 2018
3f9412a
Merge branch 'master' into components-safeareaview-oninsetschange
clmntcrl Aug 30, 2018
f0e872b
Merge branch 'master' into components-safeareaview-oninsetschange
clmntcrl Sep 5, 2018
b07d007
Merge branch 'master' into components-safeareaview-oninsetschange
clmntcrl Sep 21, 2018
97de2f6
Merge branch 'master' into components-safeareaview-oninsetschange
clmntcrl Oct 8, 2018
485286a
Merge branch 'master' into components-safeareaview-oninsetschange
hramos Mar 27, 2019
c9b52f7
Update SafeAreaViewExample.js
hramos Mar 27, 2019
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: 3 additions & 1 deletion Libraries/Components/SafeAreaView/SafeAreaView.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ const View = require('View');
const requireNativeComponent = require('requireNativeComponent');

import type {ViewProps} from 'ViewPropTypes';
import type {InsetsChangeEvent} from 'CoreEventTypes';

type Props = $ReadOnly<{|
...ViewProps,
emulateUnlessSupported?: boolean,
onInsetsChange?: ?(event: InsetsChangeEvent) => Promise<void> | void,
|}>;

let exported;
Expand All @@ -34,7 +36,7 @@ let exported;
if (Platform.OS === 'android') {
exported = class SafeAreaView extends React.Component<Props> {
render(): React.Node {
const {emulateUnlessSupported, ...props} = this.props;
const {emulateUnlessSupported, onInsetsChange, ...props} = this.props;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are destructuring the props here and then not doing anything with onInsetsChange. Do you mind patching up the code to make it work properly and making sure the test plan and example show that this is working properly?

return <View {...props} />;
}
};
Expand Down
15 changes: 14 additions & 1 deletion Libraries/Types/CoreEventTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type SyntheticEvent<T> = $ReadOnly<{|
persist: () => void,
target: ?number,
timeStamp: number,
type: ?string,
type?: ?string,
|}>;

export type Layout = $ReadOnly<{|
Expand Down Expand Up @@ -109,3 +109,16 @@ export type SwitchChangeEvent = SyntheticEvent<
value: boolean,
|}>,
>;

export type Insets = $ReadOnly<{|
left: number,
top: number,
right: number,
bottom: number,
|}>;

export type InsetsChangeEvent = SyntheticEvent<
$ReadOnly<{|
insets: Insets,
|}>,
>;
15 changes: 14 additions & 1 deletion RNTester/js/SafeAreaViewExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const Switch = require('Switch');
const Text = require('Text');
const View = require('View');

import type {Insets} from 'CoreEventTypes';

exports.displayName = (undefined: ?string);
exports.framework = 'React';
exports.title = '<SafeAreaView>';
Expand All @@ -30,17 +32,23 @@ class SafeAreaViewExample extends React.Component<
{|
modalVisible: boolean,
emulateUnlessSupported: boolean,
insets: ?Insets,
|},
> {
state = {
modalVisible: false,
emulateUnlessSupported: true,
insets: undefined,
};

_setModalVisible = visible => {
this.setState({modalVisible: visible});
};

_onSafeAreaViewInsetsChange = event => {
this.setState({insets: event.nativeEvent.insets});
};

render() {
return (
<View>
Expand All @@ -52,8 +60,13 @@ class SafeAreaViewExample extends React.Component<
<View style={styles.modal}>
<SafeAreaView
style={styles.safeArea}
emulateUnlessSupported={this.state.emulateUnlessSupported}>
emulateUnlessSupported={this.state.emulateUnlessSupported}
onInsetsChange={this._onSafeAreaViewInsetsChange}>
<View style={styles.safeAreaContent}>
<Text>
{this.state.insets &&
`safeAreaViewInsets:\n${JSON.stringify(this.state.insets)}`}
</Text>
<Button
onPress={this._setModalVisible.bind(this, false)}
title="Close"
Expand Down
14 changes: 14 additions & 0 deletions React/Views/SafeAreaView/RCTSafeAreaView.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

#import "RCTSafeAreaViewLocalData.h"

@interface RCTSafeAreaView ()

@property (nonatomic, copy) RCTBubblingEventBlock onInsetsChange;

@end

@implementation RCTSafeAreaView {
__weak RCTBridge *_bridge;
UIEdgeInsets _currentSafeAreaInsets;
Expand Down Expand Up @@ -107,6 +113,14 @@ - (void)setSafeAreaInsets:(UIEdgeInsets)safeAreaInsets

RCTSafeAreaViewLocalData *localData = [[RCTSafeAreaViewLocalData alloc] initWithInsets:safeAreaInsets];
[_bridge.uiManager setLocalData:localData forView:self];

if (_onInsetsChange) {
_onInsetsChange(@{ @"insets": @{
@"left": @(safeAreaInsets.left),
@"top": @(safeAreaInsets.top),
@"right": @(safeAreaInsets.right),
@"bottom": @(safeAreaInsets.right) } });
}
}

- (void)setEmulateUnlessSupported:(BOOL)emulateUnlessSupported
Expand Down
2 changes: 2 additions & 0 deletions React/Views/SafeAreaView/RCTSafeAreaViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ - (RCTSafeAreaShadowView *)shadowView
return [RCTSafeAreaShadowView new];
}

RCT_EXPORT_VIEW_PROPERTY(onInsetsChange, RCTBubblingEventBlock)

@end