Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,12 @@ describe('<FlatList>', () => {

timers.advanceTimersByTime(200);

// The first timer represents an intermediate viewport snapshot and
// must not publish after the final visible set supersedes it.
expect(onViewableItemsChanged).not.toHaveBeenCalled();

timers.advanceTimersByTime(200);

expect(onViewableItemsChanged).toHaveBeenCalled();
} finally {
timers.uninstall();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@ class TracingTest : public TracingTestBase<
TEST_F(TracingTest, EnablesSamplingProfilerOnlyCategoryIsSpecified) {
InSequence s;

const auto runSamplingWorkload = [this]() {
eval(R"(
const start = Date.now();
while (Date.now() - start < 10) {}
)");
};

startTracing({});
runSamplingWorkload();
auto allTraceEvents = endTracingAndCollectEvents();

EXPECT_THAT(
Expand All @@ -47,6 +55,7 @@ TEST_F(TracingTest, EnablesSamplingProfilerOnlyCategoryIsSpecified) {
AtJsonPtr("/cat", "disabled-by-default-v8.cpu_profiler")))));

startTracing({tracing::Category::JavaScriptSampling});
runSamplingWorkload();
allTraceEvents = endTracingAndCollectEvents();

EXPECT_THAT(
Expand Down
64 changes: 36 additions & 28 deletions packages/rn-tester/js/examples/Image/ImageExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,41 @@ exports.category = 'Basic';
exports.description =
'Base component for displaying different types of images.';

component BoxShadowExample() {
const [loadedImageCount, setLoadedImageCount] = useState(0);
const onLoad = () => setLoadedImageCount(count => count + 1);

return (
<View
style={styles.horizontal}
testID={loadedImageCount >= 3 ? 'box-shadow-example' : undefined}>
<Image
onLoad={onLoad}
style={[styles.base, styles.boxShadow, styles.boxShadowWithBackground]}
source={smallImage}
/>
<Image
onLoad={onLoad}
style={[
styles.base,
styles.boxShadow,
styles.boxShadowMultiOutsetInset,
]}
source={smallImage}
/>
<Image
onLoad={onLoad}
style={[
styles.base,
styles.boxShadow,
styles.boxShadowAsymetricallyRounded,
]}
source={fullImage}
/>
</View>
);
}

exports.examples = [
{
title: 'Plain Network Image with `source` prop.',
Expand Down Expand Up @@ -1488,34 +1523,7 @@ exports.examples = [
title: 'Box Shadow',
name: 'box-shadow',
render: function (): React.Node {
return (
<View style={styles.horizontal} testID="box-shadow-example">
<Image
style={[
styles.base,
styles.boxShadow,
styles.boxShadowWithBackground,
]}
source={smallImage}
/>
<Image
style={[
styles.base,
styles.boxShadow,
styles.boxShadowMultiOutsetInset,
]}
source={smallImage}
/>
<Image
style={[
styles.base,
styles.boxShadow,
styles.boxShadowAsymetricallyRounded,
]}
source={fullImage}
/>
</View>
);
return <BoxShadowExample />;
},
},
{
Expand Down
4 changes: 4 additions & 0 deletions packages/virtualized-lists/Lists/ViewabilityHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ class ViewabilityHelper {
* comment suppresses an error found when Flow v0.63 was deployed. To
* see the error delete this comment and run Flow. */
this._timers.delete(handle);
// `onUpdate` replaces the array whenever the visible set changes.
if (this._viewableIndices !== viewableIndices) {
return;
}
this._onUpdateSync(
props,
viewableIndices,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,58 @@ describe('onUpdate', function () {
});
});

it('minimumViewTime ignores stale viewability updates', function () {
const helper = new ViewabilityHelper({
minimumViewTime: 350,
viewAreaCoveragePercentThreshold: 0,
});
rowFrames = {
a: {y: 0, height: 200},
b: {y: 200, height: 200},
};
data = [{key: 'a'}, {key: 'b'}];
const onViewableItemsChanged = jest.fn();
helper.onUpdate(
props,
0,
200,
// $FlowFixMe[incompatible-type] - Invalid `ListMetricsAggregator`.
{getCellMetrics},
createViewToken,
onViewableItemsChanged,
);
helper.onUpdate(
props,
0,
400,
// $FlowFixMe[incompatible-type] - Invalid `ListMetricsAggregator`.
{getCellMetrics},
createViewToken,
onViewableItemsChanged,
);

jest.runAllTimers();

expect(onViewableItemsChanged.mock.calls).toEqual([
[
{
changed: [
{isViewable: true, key: 'a'},
{isViewable: true, key: 'b'},
],
viewabilityConfig: {
minimumViewTime: 350,
viewAreaCoveragePercentThreshold: 0,
},
viewableItems: [
{isViewable: true, key: 'a'},
{isViewable: true, key: 'b'},
],
},
],
]);
});

it('minimumViewTime skips briefly visible items', function () {
const helper = new ViewabilityHelper({
minimumViewTime: 350,
Expand Down
Loading