mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
refactor(ReactNative/Slider): moved android sources to internal
Summary: # Changelog: [Android][Removed] - removed android sources of Slider module Reviewed By: NickGerleman Differential Revision: D41062668 fbshipit-source-id: fe628527f757d4fefa8ecf2c0c952aaf8d4acec2
This commit is contained in:
1 parent
05968d16e1
commit
4c40014d43
28 files changed
-1414
No files matched your search
@@ -26,7 +26,6 @@ public class FabricComponents {
|
||||
sComponentNames.put("View", "RCTView");
|
||||
sComponentNames.put("Image", "RCTImageView");
|
||||
sComponentNames.put("ScrollView", "RCTScrollView");
|
||||
sComponentNames.put("Slider", "RCTSlider");
|
||||
sComponentNames.put("ModalHostView", "RCTModalHostView");
|
||||
sComponentNames.put("Paragraph", "RCTText");
|
||||
sComponentNames.put("Text", "RCText");
|
||||
|
||||
@@ -58,7 +58,6 @@ rn_android_library(
|
||||
react_native_target("java/com/facebook/react/views/modal:modal"),
|
||||
react_native_target("java/com/facebook/react/views/progressbar:progressbar"),
|
||||
react_native_target("java/com/facebook/react/views/scroll:scroll"),
|
||||
react_native_target("java/com/facebook/react/views/slider:slider"),
|
||||
react_native_target("java/com/facebook/react/views/swiperefresh:swiperefresh"),
|
||||
react_native_target("java/com/facebook/react/views/switchview:switchview"),
|
||||
react_native_target("java/com/facebook/react/views/text:text"),
|
||||
|
||||
@@ -46,7 +46,6 @@ import com.facebook.react.views.progressbar.ReactProgressBarViewManager;
|
||||
import com.facebook.react.views.scroll.ReactHorizontalScrollContainerViewManager;
|
||||
import com.facebook.react.views.scroll.ReactHorizontalScrollViewManager;
|
||||
import com.facebook.react.views.scroll.ReactScrollViewManager;
|
||||
import com.facebook.react.views.slider.ReactSliderManager;
|
||||
import com.facebook.react.views.swiperefresh.SwipeRefreshLayoutManager;
|
||||
import com.facebook.react.views.switchview.ReactSwitchManager;
|
||||
import com.facebook.react.views.text.ReactRawTextManager;
|
||||
@@ -158,7 +157,6 @@ public class MainReactPackage extends TurboReactPackage {
|
||||
viewManagers.add(new ReactHorizontalScrollContainerViewManager());
|
||||
viewManagers.add(new ReactProgressBarViewManager());
|
||||
viewManagers.add(new ReactScrollViewManager());
|
||||
viewManagers.add(new ReactSliderManager());
|
||||
viewManagers.add(new ReactSwitchManager());
|
||||
viewManagers.add(new SwipeRefreshLayoutManager());
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
load("//tools/build_defs/oss:rn_defs.bzl", "YOGA_TARGET", "react_native_dep", "react_native_root_target", "react_native_target", "rn_android_library")
|
||||
|
||||
rn_android_library(
|
||||
name = "slider",
|
||||
srcs = glob(["*.java"]),
|
||||
autoglob = False,
|
||||
labels = [
|
||||
"pfh:ReactNative_CommonInfrastructurePlaceholder",
|
||||
],
|
||||
language = "JAVA",
|
||||
visibility = [
|
||||
"PUBLIC",
|
||||
],
|
||||
deps = [
|
||||
YOGA_TARGET,
|
||||
react_native_dep("third-party/android/androidx:annotation"),
|
||||
react_native_dep("third-party/android/androidx:appcompat"),
|
||||
react_native_dep("third-party/android/androidx:core"),
|
||||
react_native_dep("third-party/android/androidx:fragment"),
|
||||
react_native_dep("third-party/android/androidx:legacy-support-core-ui"),
|
||||
react_native_dep("third-party/android/androidx:legacy-support-core-utils"),
|
||||
react_native_dep("third-party/java/jsr-305:jsr-305"),
|
||||
react_native_target("java/com/facebook/react/bridge:bridge"),
|
||||
react_native_target("java/com/facebook/react/common:common"),
|
||||
react_native_target("java/com/facebook/react/uimanager:uimanager"),
|
||||
react_native_target("java/com/facebook/react/uimanager/annotations:annotations"),
|
||||
react_native_root_target(":generated_components_java-FBReactNativeComponentSpec"),
|
||||
],
|
||||
)
|
||||
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.views.slider;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.AppCompatSeekBar;
|
||||
|
||||
/**
|
||||
* Slider that behaves more like the iOS one, for consistency.
|
||||
*
|
||||
* <p>On iOS, the value is 0..1. Android SeekBar only supports integer values. For consistency, we
|
||||
* pretend in JS that the value is 0..1 but set the SeekBar value to 0..100.
|
||||
*
|
||||
* <p>Note that the slider is _not_ a controlled component (setValue isn't called during dragging).
|
||||
*/
|
||||
public class ReactSlider extends AppCompatSeekBar {
|
||||
|
||||
/**
|
||||
* If step is 0 (unset) we default to this total number of steps. Don't use 100 which leads to
|
||||
* rounding errors (0.200000000001).
|
||||
*/
|
||||
private static int DEFAULT_TOTAL_STEPS = 128;
|
||||
|
||||
/**
|
||||
* We want custom min..max range. Android only supports 0..max range so we implement this
|
||||
* ourselves.
|
||||
*/
|
||||
private double mMinValue = 0;
|
||||
|
||||
private double mMaxValue = 0;
|
||||
|
||||
/**
|
||||
* Value sent from JS (setState). Doesn't get updated during drag (slider is not a controlled
|
||||
* component).
|
||||
*/
|
||||
private double mValue = 0;
|
||||
|
||||
/** If zero it's determined automatically. */
|
||||
private double mStep = 0;
|
||||
|
||||
private double mStepCalculated = 0;
|
||||
|
||||
public ReactSlider(Context context, @Nullable AttributeSet attrs, int style) {
|
||||
super(context, attrs, style);
|
||||
disableStateListAnimatorIfNeeded();
|
||||
}
|
||||
|
||||
/* package */ void disableStateListAnimatorIfNeeded() {
|
||||
// We disable the state list animator for Android 6 and 7; this is a hack to prevent T37452851
|
||||
// and https://github.com/facebook/react-native/issues/9979
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
||||
&& Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||
super.setStateListAnimator(null);
|
||||
}
|
||||
}
|
||||
|
||||
/* package */ void setMaxValue(double max) {
|
||||
mMaxValue = max;
|
||||
updateAll();
|
||||
}
|
||||
|
||||
/* package */ void setMinValue(double min) {
|
||||
mMinValue = min;
|
||||
updateAll();
|
||||
}
|
||||
|
||||
/* package */ void setValue(double value) {
|
||||
mValue = value;
|
||||
updateValue();
|
||||
}
|
||||
|
||||
/* package */ void setStep(double step) {
|
||||
mStep = step;
|
||||
updateAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert SeekBar's native progress value (e.g. 0..100) to a value passed to JS (e.g. -1.0..2.5).
|
||||
*/
|
||||
public double toRealProgress(int seekBarProgress) {
|
||||
if (seekBarProgress == getMax()) {
|
||||
return mMaxValue;
|
||||
}
|
||||
return seekBarProgress * getStepValue() + mMinValue;
|
||||
}
|
||||
|
||||
/** Update underlying native SeekBar's values. */
|
||||
private void updateAll() {
|
||||
if (mStep == 0) {
|
||||
mStepCalculated = (mMaxValue - mMinValue) / (double) DEFAULT_TOTAL_STEPS;
|
||||
}
|
||||
setMax(getTotalSteps());
|
||||
updateValue();
|
||||
}
|
||||
|
||||
/** Update value only (optimization in case only value is set). */
|
||||
private void updateValue() {
|
||||
setProgress((int) Math.round((mValue - mMinValue) / (mMaxValue - mMinValue) * getTotalSteps()));
|
||||
}
|
||||
|
||||
private int getTotalSteps() {
|
||||
return (int) Math.ceil((mMaxValue - mMinValue) / getStepValue());
|
||||
}
|
||||
|
||||
private double getStepValue() {
|
||||
return mStep > 0 ? mStep : mStepCalculated;
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.views.slider;
|
||||
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import com.facebook.react.uimanager.events.Event;
|
||||
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
||||
|
||||
/** Event emitted by a ReactSliderManager when user changes slider position. */
|
||||
public class ReactSliderEvent extends Event<ReactSliderEvent> {
|
||||
|
||||
public static final String EVENT_NAME = "topValueChange";
|
||||
|
||||
private final double mValue;
|
||||
private final boolean mFromUser;
|
||||
|
||||
public ReactSliderEvent(int viewId, double value, boolean fromUser) {
|
||||
super(viewId);
|
||||
mValue = value;
|
||||
mFromUser = fromUser;
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
return mValue;
|
||||
}
|
||||
|
||||
public boolean isFromUser() {
|
||||
return mFromUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventName() {
|
||||
return EVENT_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatch(RCTEventEmitter rctEventEmitter) {
|
||||
rctEventEmitter.receiveEvent(getViewTag(), getEventName(), serializeEventData());
|
||||
}
|
||||
|
||||
private WritableMap serializeEventData() {
|
||||
WritableMap eventData = Arguments.createMap();
|
||||
eventData.putInt("target", getViewTag());
|
||||
eventData.putDouble("value", getValue());
|
||||
eventData.putBoolean("fromUser", isFromUser());
|
||||
return eventData;
|
||||
}
|
||||
}
|
||||
@@ -1,336 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.views.slider;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.SeekBar;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.AccessibilityActionCompat;
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.common.MapBuilder;
|
||||
import com.facebook.react.uimanager.LayoutShadowNode;
|
||||
import com.facebook.react.uimanager.PixelUtil;
|
||||
import com.facebook.react.uimanager.ReactAccessibilityDelegate;
|
||||
import com.facebook.react.uimanager.SimpleViewManager;
|
||||
import com.facebook.react.uimanager.ThemedReactContext;
|
||||
import com.facebook.react.uimanager.UIManagerHelper;
|
||||
import com.facebook.react.uimanager.ViewManagerDelegate;
|
||||
import com.facebook.react.uimanager.ViewProps;
|
||||
import com.facebook.react.uimanager.annotations.ReactProp;
|
||||
import com.facebook.react.uimanager.events.EventDispatcher;
|
||||
import com.facebook.react.viewmanagers.SliderManagerDelegate;
|
||||
import com.facebook.react.viewmanagers.SliderManagerInterface;
|
||||
import com.facebook.yoga.YogaMeasureFunction;
|
||||
import com.facebook.yoga.YogaMeasureMode;
|
||||
import com.facebook.yoga.YogaMeasureOutput;
|
||||
import com.facebook.yoga.YogaNode;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Manages instances of {@code ReactSlider}.
|
||||
*
|
||||
* <p>Note that the slider is _not_ a controlled component.
|
||||
*/
|
||||
public class ReactSliderManager extends SimpleViewManager<ReactSlider>
|
||||
implements SliderManagerInterface<ReactSlider> {
|
||||
|
||||
private static final int STYLE = android.R.attr.seekBarStyle;
|
||||
|
||||
public static final String REACT_CLASS = "RCTSlider";
|
||||
|
||||
static class ReactSliderShadowNode extends LayoutShadowNode implements YogaMeasureFunction {
|
||||
|
||||
private int mWidth;
|
||||
private int mHeight;
|
||||
private boolean mMeasured;
|
||||
|
||||
private ReactSliderShadowNode() {
|
||||
initMeasureFunction();
|
||||
}
|
||||
|
||||
private void initMeasureFunction() {
|
||||
setMeasureFunction(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long measure(
|
||||
YogaNode node,
|
||||
float width,
|
||||
YogaMeasureMode widthMode,
|
||||
float height,
|
||||
YogaMeasureMode heightMode) {
|
||||
if (!mMeasured) {
|
||||
ReactSlider reactSlider = new ReactSlider(getThemedContext(), null, STYLE);
|
||||
// reactSlider is used for measurements purposes, it is not necessary to set a
|
||||
// StateListAnimator.
|
||||
// It is not safe to access StateListAnimator from a background thread.
|
||||
reactSlider.disableStateListAnimatorIfNeeded();
|
||||
final int spec =
|
||||
View.MeasureSpec.makeMeasureSpec(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT, View.MeasureSpec.UNSPECIFIED);
|
||||
reactSlider.measure(spec, spec);
|
||||
mWidth = reactSlider.getMeasuredWidth();
|
||||
mHeight = reactSlider.getMeasuredHeight();
|
||||
mMeasured = true;
|
||||
}
|
||||
|
||||
return YogaMeasureOutput.make(mWidth, mHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private static final SeekBar.OnSeekBarChangeListener ON_CHANGE_LISTENER =
|
||||
new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekbar, int progress, boolean fromUser) {
|
||||
ReactContext reactContext = (ReactContext) seekbar.getContext();
|
||||
EventDispatcher eventDispatcher =
|
||||
UIManagerHelper.getEventDispatcherForReactTag(reactContext, seekbar.getId());
|
||||
|
||||
if (eventDispatcher != null) {
|
||||
eventDispatcher.dispatchEvent(
|
||||
new ReactSliderEvent(
|
||||
seekbar.getId(), ((ReactSlider) seekbar).toRealProgress(progress), fromUser));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekbar) {}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekbar) {
|
||||
ReactContext reactContext = (ReactContext) seekbar.getContext();
|
||||
EventDispatcher eventDispatcher =
|
||||
UIManagerHelper.getEventDispatcherForReactTag(reactContext, seekbar.getId());
|
||||
|
||||
if (eventDispatcher != null) {
|
||||
eventDispatcher.dispatchEvent(
|
||||
new ReactSlidingCompleteEvent(
|
||||
UIManagerHelper.getSurfaceId(seekbar),
|
||||
seekbar.getId(),
|
||||
((ReactSlider) seekbar).toRealProgress(seekbar.getProgress())));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final ViewManagerDelegate<ReactSlider> mDelegate;
|
||||
|
||||
public ReactSliderManager() {
|
||||
mDelegate = new SliderManagerDelegate<>(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return REACT_CLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LayoutShadowNode createShadowNodeInstance() {
|
||||
return new ReactSliderShadowNode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getShadowNodeClass() {
|
||||
return ReactSliderShadowNode.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReactSlider createViewInstance(ThemedReactContext context) {
|
||||
final ReactSlider slider = new ReactSlider(context, null, STYLE);
|
||||
ReactSliderAccessibilityDelegate.setDelegate(
|
||||
slider, slider.isFocusable(), slider.getImportantForAccessibility());
|
||||
return slider;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ReactProp(name = ViewProps.ENABLED, defaultBoolean = true)
|
||||
public void setEnabled(ReactSlider view, boolean enabled) {
|
||||
view.setEnabled(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ReactProp(name = "value", defaultDouble = 0d)
|
||||
public void setValue(ReactSlider view, double value) {
|
||||
view.setOnSeekBarChangeListener(null);
|
||||
view.setValue(value);
|
||||
view.setOnSeekBarChangeListener(ON_CHANGE_LISTENER);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ReactProp(name = "minimumValue", defaultDouble = 0d)
|
||||
public void setMinimumValue(ReactSlider view, double value) {
|
||||
view.setMinValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ReactProp(name = "maximumValue", defaultDouble = 1d)
|
||||
public void setMaximumValue(ReactSlider view, double value) {
|
||||
view.setMaxValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ReactProp(name = "step", defaultDouble = 0d)
|
||||
public void setStep(ReactSlider view, double value) {
|
||||
view.setStep(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ReactProp(name = "thumbTintColor", customType = "Color")
|
||||
public void setThumbTintColor(ReactSlider view, Integer color) {
|
||||
if (color == null) {
|
||||
view.getThumb().clearColorFilter();
|
||||
} else {
|
||||
view.getThumb().setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ReactProp(name = "minimumTrackTintColor", customType = "Color")
|
||||
public void setMinimumTrackTintColor(ReactSlider view, Integer color) {
|
||||
LayerDrawable drawable = (LayerDrawable) view.getProgressDrawable().getCurrent();
|
||||
Drawable progress = drawable.findDrawableByLayerId(android.R.id.progress);
|
||||
if (color == null) {
|
||||
progress.clearColorFilter();
|
||||
} else {
|
||||
progress.setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ReactProp(name = "maximumTrackTintColor", customType = "Color")
|
||||
public void setMaximumTrackTintColor(ReactSlider view, Integer color) {
|
||||
LayerDrawable drawable = (LayerDrawable) view.getProgressDrawable().getCurrent();
|
||||
Drawable background = drawable.findDrawableByLayerId(android.R.id.background);
|
||||
if (color == null) {
|
||||
background.clearColorFilter();
|
||||
} else {
|
||||
background.setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ReactProp(name = "disabled")
|
||||
public void setDisabled(ReactSlider view, boolean value) {}
|
||||
|
||||
@Override
|
||||
@ReactProp(name = "maximumTrackImage", customType = "ImageSource")
|
||||
public void setMaximumTrackImage(ReactSlider view, @Nullable ReadableMap value) {}
|
||||
|
||||
@Override
|
||||
@ReactProp(name = "minimumTrackImage", customType = "ImageSource")
|
||||
public void setMinimumTrackImage(ReactSlider view, @Nullable ReadableMap value) {}
|
||||
|
||||
@Override
|
||||
public void setTestID(ReactSlider view, @Nullable String value) {
|
||||
super.setTestId(view, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ReactProp(name = "thumbImage", customType = "ImageSource")
|
||||
public void setThumbImage(ReactSlider view, @Nullable ReadableMap value) {}
|
||||
|
||||
@Override
|
||||
@ReactProp(name = "trackImage", customType = "ImageSource")
|
||||
public void setTrackImage(ReactSlider view, @Nullable ReadableMap value) {}
|
||||
|
||||
@Override
|
||||
protected void addEventEmitters(final ThemedReactContext reactContext, final ReactSlider view) {
|
||||
view.setOnSeekBarChangeListener(ON_CHANGE_LISTENER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map getExportedCustomDirectEventTypeConstants() {
|
||||
@Nullable
|
||||
Map<String, Object> baseEventTypeConstants = super.getExportedCustomDirectEventTypeConstants();
|
||||
Map<String, Object> eventTypeConstants =
|
||||
baseEventTypeConstants == null ? new HashMap<String, Object>() : baseEventTypeConstants;
|
||||
eventTypeConstants.putAll(
|
||||
MapBuilder.of(
|
||||
ReactSlidingCompleteEvent.EVENT_NAME,
|
||||
MapBuilder.of("registrationName", "onSlidingComplete")));
|
||||
return eventTypeConstants;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Map<String, Object> getExportedCustomBubblingEventTypeConstants() {
|
||||
@Nullable
|
||||
Map<String, Object> baseEventTypeConstants =
|
||||
super.getExportedCustomBubblingEventTypeConstants();
|
||||
Map<String, Object> eventTypeConstants =
|
||||
baseEventTypeConstants == null ? new HashMap<String, Object>() : baseEventTypeConstants;
|
||||
eventTypeConstants.putAll(
|
||||
MapBuilder.<String, Object>builder()
|
||||
.put(
|
||||
"topValueChange",
|
||||
MapBuilder.of(
|
||||
"phasedRegistrationNames",
|
||||
MapBuilder.of("bubbled", "onValueChange", "captured", "onValueChangeCapture")))
|
||||
.build());
|
||||
return eventTypeConstants;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long measure(
|
||||
Context context,
|
||||
ReadableMap localData,
|
||||
ReadableMap props,
|
||||
ReadableMap state,
|
||||
float width,
|
||||
YogaMeasureMode widthMode,
|
||||
float height,
|
||||
YogaMeasureMode heightMode,
|
||||
@Nullable float[] attachmentsPositions) {
|
||||
SeekBar reactSlider = new ReactSlider(context, null, STYLE);
|
||||
final int spec =
|
||||
View.MeasureSpec.makeMeasureSpec(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT, View.MeasureSpec.UNSPECIFIED);
|
||||
reactSlider.measure(spec, spec);
|
||||
|
||||
return YogaMeasureOutput.make(
|
||||
PixelUtil.toDIPFromPixel(reactSlider.getMeasuredWidth()),
|
||||
PixelUtil.toDIPFromPixel(reactSlider.getMeasuredHeight()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ViewManagerDelegate<ReactSlider> getDelegate() {
|
||||
return mDelegate;
|
||||
}
|
||||
|
||||
protected class ReactSliderAccessibilityDelegate extends ReactAccessibilityDelegate {
|
||||
public ReactSliderAccessibilityDelegate(
|
||||
final View view, boolean originalFocus, int originalImportantForAccessibility) {
|
||||
super(view, originalFocus, originalImportantForAccessibility);
|
||||
}
|
||||
|
||||
private boolean isSliderAction(int action) {
|
||||
return (action == AccessibilityActionCompat.ACTION_SCROLL_FORWARD.getId())
|
||||
|| (action == AccessibilityActionCompat.ACTION_SCROLL_BACKWARD.getId())
|
||||
|| (action == AccessibilityActionCompat.ACTION_SET_PROGRESS.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performAccessibilityAction(View host, int action, Bundle args) {
|
||||
if (isSliderAction(action)) {
|
||||
ON_CHANGE_LISTENER.onStartTrackingTouch((SeekBar) host);
|
||||
}
|
||||
final boolean rv = super.performAccessibilityAction(host, action, args);
|
||||
if (isSliderAction(action)) {
|
||||
ON_CHANGE_LISTENER.onStopTrackingTouch((SeekBar) host);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
};
|
||||
}
|
||||
-54
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.views.slider;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import com.facebook.react.uimanager.events.Event;
|
||||
|
||||
/** Event emitted when the user finishes dragging the slider. */
|
||||
public class ReactSlidingCompleteEvent extends Event<ReactSlidingCompleteEvent> {
|
||||
|
||||
public static final String EVENT_NAME = "topSlidingComplete";
|
||||
|
||||
private final double mValue;
|
||||
|
||||
@Deprecated
|
||||
public ReactSlidingCompleteEvent(int viewId, double value) {
|
||||
this(-1, viewId, value);
|
||||
}
|
||||
|
||||
public ReactSlidingCompleteEvent(int surfaceId, int viewId, double value) {
|
||||
super(surfaceId, viewId);
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
return mValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventName() {
|
||||
return EVENT_NAME;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected WritableMap getEventData() {
|
||||
WritableMap eventData = Arguments.createMap();
|
||||
eventData.putInt("target", getViewTag());
|
||||
eventData.putDouble("value", getValue());
|
||||
return eventData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCoalesce() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user