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

[pull] master from facebook:master #675

Merged
merged 6 commits into from
Mar 30, 2021
Merged
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
8 changes: 7 additions & 1 deletion Libraries/Components/ScrollView/ScrollViewStickyHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import Platform from '../../Utilities/Platform';

import type {LayoutEvent} from '../../Types/CoreEventTypes';

import ScrollViewStickyHeaderInjection from './ScrollViewStickyHeaderInjection';

const AnimatedView = AnimatedImplementation.createAnimatedComponent(View);

export type Props = $ReadOnly<{
Expand Down Expand Up @@ -328,4 +330,8 @@ const styles = StyleSheet.create({
},
});

module.exports = ScrollViewStickyHeader;
const SHToExport: React.AbstractComponent<
Props,
$ReadOnly<{setNextHeaderY: number => void, ...}>,
> = ScrollViewStickyHeaderInjection.unstable_SH ?? ScrollViewStickyHeader;
module.exports = SHToExport;
17 changes: 17 additions & 0 deletions Libraries/Components/ScrollView/ScrollViewStickyHeaderInjection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/

'use strict';

import typeof ScrollViewStickyHeader from './ScrollViewStickyHeader';

export default {
unstable_SH: (null: ?ScrollViewStickyHeader),
};
12 changes: 4 additions & 8 deletions Libraries/Components/Switch/Switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,25 +210,21 @@ class Switch extends React.Component<Props> {
// This is necessary in case native updates the switch and JS decides
// that the update should be ignored and we should stick with the value
// that we have in JS.
const nativeProps = {};
const value = this.props.value === true;

if (this._lastNativeValue !== value) {
nativeProps.value = value;
}
const nativeValue = this._lastNativeValue !== value ? value : null;

if (
Object.keys(nativeProps).length > 0 &&
nativeValue != null &&
this._nativeSwitchRef &&
this._nativeSwitchRef.setNativeProps
) {
if (Platform.OS === 'android') {
AndroidSwitchCommands.setNativeValue(
this._nativeSwitchRef,
nativeProps.value,
nativeValue,
);
} else {
SwitchCommands.setValue(this._nativeSwitchRef, nativeProps.value);
SwitchCommands.setValue(this._nativeSwitchRef, nativeValue);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,27 @@ void PrintMutationInstructionRelative(

// This corresponds exactly with JS.
enum class AnimationType {
None,
Spring,
Linear,
EaseInEaseOut,
EaseIn,
EaseOut,
Keyboard
None = 0,
Spring = 1,
Linear = 2,
EaseInEaseOut = 4,
EaseIn = 8,
EaseOut = 16,
Keyboard = 32
};
enum class AnimationProperty {
NotApplicable,
Opacity,
ScaleX,
ScaleY,
ScaleXY
NotApplicable = 0,
Opacity = 1,
ScaleX = 2,
ScaleY = 4,
ScaleXY = 8
};
enum class AnimationConfigurationType {
Noop, // for animation placeholders that are not animated, and should be
Noop = 0, // for animation placeholders that are not animated, and should be
// executed once other animations have completed
Create,
Update,
Delete
Create = 1,
Update = 2,
Delete = 4
};

// This corresponds exactly with JS.
Expand Down
11 changes: 5 additions & 6 deletions ReactCommon/react/renderer/graphics/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ namespace react {
#pragma mark - Color

inline void fromRawValue(const RawValue &value, SharedColor &result) {
float red;
float green;
float blue;
float alpha;
float red = 0;
float green = 0;
float blue = 0;
float alpha = 0;

if (value.hasType<int>()) {
auto argb = (int64_t)value;
Expand All @@ -40,9 +40,8 @@ inline void fromRawValue(const RawValue &value, SharedColor &result) {
green = items.at(1);
blue = items.at(2);
alpha = length == 4 ? items.at(3) : 1.0f;
} else {
abort();
}

result = colorFromComponents({red, green, blue, alpha});
}

Expand Down
5 changes: 5 additions & 0 deletions ReactCommon/react/renderer/mounting/StubViewTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ void StubViewTree::mutate(ShadowViewMutationList const &mutations) {
registry.find(mutation.newChildShadowView.tag) != registry.end());
auto oldStubView = registry[mutation.newChildShadowView.tag];
react_native_assert(oldStubView->tag != 0);
if ((ShadowView)(*oldStubView) != mutation.oldChildShadowView) {
LOG(ERROR)
<< "UPDATE mutation assertion failure: oldChildShadowView doesn't match oldStubView: ["
<< mutation.oldChildShadowView.tag << "]";
}
react_native_assert(
(ShadowView)(*oldStubView) == mutation.oldChildShadowView);
oldStubView->update(mutation.newChildShadowView);
Expand Down
13 changes: 12 additions & 1 deletion packages/rn-tester/js/examples/Switch/SwitchExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class ColorSwitchExample extends React.Component<{...}, $FlowFixMeState> {
return (
<View>
<Switch
testID="initial-false-switch"
onValueChange={value => this.setState({colorFalseSwitchIsOn: value})}
style={{marginBottom: 10}}
thumbColor="#0000ff"
Expand All @@ -145,6 +146,7 @@ class ColorSwitchExample extends React.Component<{...}, $FlowFixMeState> {
value={this.state.colorFalseSwitchIsOn}
/>
<Switch
testID="initial-true-switch"
onValueChange={value => this.setState({colorTrueSwitchIsOn: value})}
thumbColor="#0000ff"
trackColor={{
Expand All @@ -169,11 +171,13 @@ class EventSwitchExample extends React.Component<{...}, $FlowFixMeState> {
<View style={{flexDirection: 'row', justifyContent: 'space-around'}}>
<View>
<Switch
testID="event-switch-top"
onValueChange={value => this.setState({eventSwitchIsOn: value})}
style={{marginBottom: 10}}
value={this.state.eventSwitchIsOn}
/>
<Switch
testID="event-switch-bottom"
onValueChange={value => this.setState({eventSwitchIsOn: value})}
style={{marginBottom: 10}}
value={this.state.eventSwitchIsOn}
Expand All @@ -182,13 +186,15 @@ class EventSwitchExample extends React.Component<{...}, $FlowFixMeState> {
</View>
<View>
<Switch
testID="event-switch-regression-top"
onValueChange={value =>
this.setState({eventSwitchRegressionIsOn: value})
}
style={{marginBottom: 10}}
value={this.state.eventSwitchRegressionIsOn}
/>
<Switch
testID="event-switch-regression-bottom"
onValueChange={value =>
this.setState({eventSwitchRegressionIsOn: value})
}
Expand All @@ -210,30 +216,35 @@ exports.description = 'Native boolean input';
exports.examples = [
{
title: 'Switches can be set to true or false',
name: 'basic',
render(): React.Element<any> {
return <BasicSwitchExample />;
},
},
{
title: 'Switches can be disabled',
name: 'disabled',
render(): React.Element<any> {
return <DisabledSwitchExample />;
},
},
{
title: 'Change events can be detected',
name: 'events',
render(): React.Element<any> {
return <EventSwitchExample />;
},
},
{
title: 'Switches are controlled components',
name: 'controlled',
render(): React.Element<any> {
return <Switch />;
return <Switch testID="controlled-switch" />;
},
},
{
title: 'Custom colors can be provided',
name: 'custom-colors',
render(): React.Element<any> {
return <ColorSwitchExample />;
},
Expand Down