mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-03 17:45:12 +08:00
Summary: The nodes version of D3364550. The only difference is that here we don't get `onSizeChanged` but `onBoundsChanged`, and we need to compute the height/width of the target image from those bounds. ahmedre please let me know if any of these assumptions are in any way incorrect. Reviewed By: ahmedre Differential Revision: D3424843
41 lines
1.3 KiB
Java
41 lines
1.3 KiB
Java
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
package com.facebook.react.flat;
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* Helper class for computing the source to be used for an Image.
|
|
*/
|
|
/* package */ class MultiSourceImageHelper {
|
|
|
|
/**
|
|
* Chooses the image source with the size closest to the target image size. Must be called only
|
|
* after the layout pass when the sizes of the target image have been computed, and when there
|
|
* are at least two sources to choose from.
|
|
*/
|
|
public static @Nullable String getImageSourceFromMultipleSources(
|
|
double targetImageSize,
|
|
Map<String, Double> sources) {
|
|
double bestPrecision = Double.MAX_VALUE;
|
|
String imageSource = null;
|
|
for (Map.Entry<String, Double> source : sources.entrySet()) {
|
|
final double precision = Math.abs(1.0 - (source.getValue()) / targetImageSize);
|
|
if (precision < bestPrecision) {
|
|
bestPrecision = precision;
|
|
imageSource = source.getKey();
|
|
}
|
|
}
|
|
return imageSource;
|
|
}
|
|
}
|