From 4c40014d43abe88b17db75aca9de9cca349ecbcc Mon Sep 17 00:00:00 2001 From: Ruslan Lesiutin Date: Thu, 5 Jan 2023 06:12:47 -0800 Subject: [PATCH] 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 --- BUCK | 1 - .../java/com/facebook/react/tests/BUCK | 1 - .../react/fabric/FabricComponents.java | 1 - .../main/java/com/facebook/react/shell/BUCK | 1 - .../react/shell/MainReactPackage.java | 2 - .../java/com/facebook/react/views/slider/BUCK | 29 -- .../react/views/slider/ReactSlider.java | 116 ------ .../react/views/slider/ReactSliderEvent.java | 54 --- .../views/slider/ReactSliderManager.java | 336 ------------------ .../slider/ReactSlidingCompleteEvent.java | 54 --- ReactAndroid/src/main/jni/CMakeLists.txt | 1 - ReactAndroid/src/main/jni/react/fabric/BUCK | 1 - .../src/main/jni/react/fabric/CMakeLists.txt | 1 - .../react/fabric/CoreComponentsRegistry.cpp | 3 - .../test/java/com/facebook/react/views/BUCK | 1 - .../views/slider/ReactSliderPropertyTest.java | 100 ------ .../react/renderer/components/slider/BUCK | 117 ------ .../renderer/components/slider/CMakeLists.txt | 45 --- .../slider/SliderComponentDescriptor.h | 58 --- .../components/slider/SliderShadowNode.cpp | 100 ------ .../components/slider/SliderShadowNode.h | 77 ---- .../components/slider/SliderState.cpp | 44 --- .../renderer/components/slider/SliderState.h | 89 ----- .../slider/SliderMeasurementsManager.cpp | 72 ---- .../slider/SliderMeasurementsManager.h | 40 --- .../ios/SliderMeasurementsManager.cpp | 23 -- .../platform/ios/SliderMeasurementsManager.h | 33 -- .../components/slider/tests/SliderTest.cpp | 14 - 28 files changed, 1414 deletions(-) delete mode 100644 ReactAndroid/src/main/java/com/facebook/react/views/slider/BUCK delete mode 100644 ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSlider.java delete mode 100644 ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSliderEvent.java delete mode 100644 ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSliderManager.java delete mode 100644 ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSlidingCompleteEvent.java delete mode 100644 ReactAndroid/src/test/java/com/facebook/react/views/slider/ReactSliderPropertyTest.java delete mode 100644 ReactCommon/react/renderer/components/slider/BUCK delete mode 100644 ReactCommon/react/renderer/components/slider/CMakeLists.txt delete mode 100644 ReactCommon/react/renderer/components/slider/SliderComponentDescriptor.h delete mode 100644 ReactCommon/react/renderer/components/slider/SliderShadowNode.cpp delete mode 100644 ReactCommon/react/renderer/components/slider/SliderShadowNode.h delete mode 100644 ReactCommon/react/renderer/components/slider/SliderState.cpp delete mode 100644 ReactCommon/react/renderer/components/slider/SliderState.h delete mode 100644 ReactCommon/react/renderer/components/slider/platform/android/react/renderer/components/slider/SliderMeasurementsManager.cpp delete mode 100644 ReactCommon/react/renderer/components/slider/platform/android/react/renderer/components/slider/SliderMeasurementsManager.h delete mode 100644 ReactCommon/react/renderer/components/slider/platform/ios/SliderMeasurementsManager.cpp delete mode 100644 ReactCommon/react/renderer/components/slider/platform/ios/SliderMeasurementsManager.h delete mode 100644 ReactCommon/react/renderer/components/slider/tests/SliderTest.cpp diff --git a/BUCK b/BUCK index 25fe38e6a3acee..e265bb6b450e70 100644 --- a/BUCK +++ b/BUCK @@ -563,7 +563,6 @@ rn_apple_xplat_cxx_library( exported_deps = [ react_native_xplat_target("react/renderer/animations:animations"), react_native_xplat_target("react/renderer/components/scrollview:scrollview"), - react_native_xplat_target("react/renderer/components/slider:slider"), react_native_xplat_target("react/renderer/components/safeareaview:safeareaview"), react_native_xplat_target("react/renderer/components/modal:modal"), react_native_xplat_target("react/renderer/components/unimplementedview:unimplementedview"), diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/tests/BUCK b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/BUCK index 5b08ffe862f6d8..2cef6d1efbe096 100644 --- a/ReactAndroid/src/androidTest/java/com/facebook/react/tests/BUCK +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/BUCK @@ -34,7 +34,6 @@ rn_android_library( react_native_target("java/com/facebook/react/uimanager/util:util"), 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/text:text"), react_native_target("java/com/facebook/react/views/textinput:textinput"), diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricComponents.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricComponents.java index bf6c6a2aaa36d8..2ae94696fadffd 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricComponents.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricComponents.java @@ -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"); diff --git a/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK b/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK index 5ea6716012c739..6becaa20ade9ed 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK @@ -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"), diff --git a/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java b/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java index df4a46adacf91e..60a5be970d4547 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java +++ b/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java @@ -46,7 +46,6 @@ 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 List createViewManagers(ReactApplicationContext reactContext viewManagers.add(new ReactHorizontalScrollContainerViewManager()); viewManagers.add(new ReactProgressBarViewManager()); viewManagers.add(new ReactScrollViewManager()); - viewManagers.add(new ReactSliderManager()); viewManagers.add(new ReactSwitchManager()); viewManagers.add(new SwipeRefreshLayoutManager()); diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/slider/BUCK b/ReactAndroid/src/main/java/com/facebook/react/views/slider/BUCK deleted file mode 100644 index e402f20b8b6d86..00000000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/views/slider/BUCK +++ /dev/null @@ -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"), - ], -) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSlider.java b/ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSlider.java deleted file mode 100644 index d255cb6e3bcb2b..00000000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSlider.java +++ /dev/null @@ -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. - * - *

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. - * - *

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; - } -} diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSliderEvent.java b/ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSliderEvent.java deleted file mode 100644 index 8f97341d2956ab..00000000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSliderEvent.java +++ /dev/null @@ -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 { - - 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; - } -} diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSliderManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSliderManager.java deleted file mode 100644 index 86cbe70bcc3308..00000000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSliderManager.java +++ /dev/null @@ -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}. - * - *

Note that the slider is _not_ a controlled component. - */ -public class ReactSliderManager extends SimpleViewManager - implements SliderManagerInterface { - - 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 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 baseEventTypeConstants = super.getExportedCustomDirectEventTypeConstants(); - Map eventTypeConstants = - baseEventTypeConstants == null ? new HashMap() : baseEventTypeConstants; - eventTypeConstants.putAll( - MapBuilder.of( - ReactSlidingCompleteEvent.EVENT_NAME, - MapBuilder.of("registrationName", "onSlidingComplete"))); - return eventTypeConstants; - } - - @Nullable - @Override - public Map getExportedCustomBubblingEventTypeConstants() { - @Nullable - Map baseEventTypeConstants = - super.getExportedCustomBubblingEventTypeConstants(); - Map eventTypeConstants = - baseEventTypeConstants == null ? new HashMap() : baseEventTypeConstants; - eventTypeConstants.putAll( - MapBuilder.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 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; - } - }; -} diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSlidingCompleteEvent.java b/ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSlidingCompleteEvent.java deleted file mode 100644 index b1c249b7cc4619..00000000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSlidingCompleteEvent.java +++ /dev/null @@ -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 { - - 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; - } -} diff --git a/ReactAndroid/src/main/jni/CMakeLists.txt b/ReactAndroid/src/main/jni/CMakeLists.txt index 6d0789f930e500..7bc36325b689e7 100644 --- a/ReactAndroid/src/main/jni/CMakeLists.txt +++ b/ReactAndroid/src/main/jni/CMakeLists.txt @@ -82,7 +82,6 @@ add_react_common_subdir(react/renderer/components/view) add_react_common_subdir(react/renderer/components/switch) add_react_common_subdir(react/renderer/components/textinput) add_react_common_subdir(react/renderer/components/progressbar) -add_react_common_subdir(react/renderer/components/slider) add_react_common_subdir(react/renderer/components/root) add_react_common_subdir(react/renderer/components/image) add_react_common_subdir(react/renderer/componentregistry/native) diff --git a/ReactAndroid/src/main/jni/react/fabric/BUCK b/ReactAndroid/src/main/jni/react/fabric/BUCK index 49de510dda3c76..5172ec4eec5f60 100644 --- a/ReactAndroid/src/main/jni/react/fabric/BUCK +++ b/ReactAndroid/src/main/jni/react/fabric/BUCK @@ -45,7 +45,6 @@ rn_xplat_cxx_library( "//xplat/js/react-native-github:generated_components-rncore", react_native_xplat_target("react/renderer/components/image:image"), react_native_xplat_target("react/renderer/components/modal:modal"), - react_native_xplat_target("react/renderer/components/slider:slider"), react_native_xplat_target("react/renderer/components/switch:androidswitch"), react_native_xplat_target("react/renderer/components/progressbar:androidprogressbar"), react_native_xplat_target("react/renderer/components/text:text"), diff --git a/ReactAndroid/src/main/jni/react/fabric/CMakeLists.txt b/ReactAndroid/src/main/jni/react/fabric/CMakeLists.txt index c4d743cfa10e7b..865dbb262bba71 100644 --- a/ReactAndroid/src/main/jni/react/fabric/CMakeLists.txt +++ b/ReactAndroid/src/main/jni/react/fabric/CMakeLists.txt @@ -50,7 +50,6 @@ target_link_libraries( rrc_progressbar rrc_root rrc_scrollview - rrc_slider rrc_switch rrc_text rrc_textinput diff --git a/ReactAndroid/src/main/jni/react/fabric/CoreComponentsRegistry.cpp b/ReactAndroid/src/main/jni/react/fabric/CoreComponentsRegistry.cpp index 22f1ddeb439d82..1c6b043ff6f62c 100644 --- a/ReactAndroid/src/main/jni/react/fabric/CoreComponentsRegistry.cpp +++ b/ReactAndroid/src/main/jni/react/fabric/CoreComponentsRegistry.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -58,8 +57,6 @@ CoreComponentsRegistry::sharedProviderRegistry() { concreteComponentDescriptorProvider()); providerRegistry->add( concreteComponentDescriptorProvider()); - providerRegistry->add( - concreteComponentDescriptorProvider()); providerRegistry->add( concreteComponentDescriptorProvider()); providerRegistry->add( diff --git a/ReactAndroid/src/test/java/com/facebook/react/views/BUCK b/ReactAndroid/src/test/java/com/facebook/react/views/BUCK index 8a3f5f828798d6..808e21b9f8d959 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/views/BUCK +++ b/ReactAndroid/src/test/java/com/facebook/react/views/BUCK @@ -35,7 +35,6 @@ rn_robolectric_test( react_native_target("java/com/facebook/react/uimanager:uimanager"), react_native_target("java/com/facebook/react/uimanager/annotations:annotations"), react_native_target("java/com/facebook/react/views/image:image"), - react_native_target("java/com/facebook/react/views/slider:slider"), react_native_target("java/com/facebook/react/views/text:text"), react_native_target("java/com/facebook/react/views/textinput:textinput"), react_native_target("java/com/facebook/react/views/view:view"), diff --git a/ReactAndroid/src/test/java/com/facebook/react/views/slider/ReactSliderPropertyTest.java b/ReactAndroid/src/test/java/com/facebook/react/views/slider/ReactSliderPropertyTest.java deleted file mode 100644 index 71453966cb4658..00000000000000 --- a/ReactAndroid/src/test/java/com/facebook/react/views/slider/ReactSliderPropertyTest.java +++ /dev/null @@ -1,100 +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 static org.assertj.core.api.Assertions.assertThat; - -import android.widget.SeekBar; -import com.facebook.react.bridge.CatalystInstance; -import com.facebook.react.bridge.JavaOnlyMap; -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.bridge.ReactTestHelper; -import com.facebook.react.uimanager.ReactStylesDiffMap; -import com.facebook.react.uimanager.ThemedReactContext; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.modules.junit4.rule.PowerMockRule; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.RuntimeEnvironment; - -/** Verify {@link SeekBar} view property being applied properly by {@link ReactSliderManager} */ -@RunWith(RobolectricTestRunner.class) -@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"}) -public class ReactSliderPropertyTest { - - @Rule public PowerMockRule rule = new PowerMockRule(); - - private ThemedReactContext mThemedContext; - private ReactSliderManager mManager; - - @Before - public void setup() { - ReactApplicationContext mContext = new ReactApplicationContext(RuntimeEnvironment.application); - CatalystInstance mCatalystInstanceMock = ReactTestHelper.createMockCatalystInstance(); - mContext.initializeWithInstance(mCatalystInstanceMock); - mThemedContext = new ThemedReactContext(mContext, mContext); - mManager = new ReactSliderManager(); - } - - public ReactStylesDiffMap buildStyles(Object... keysAndValues) { - return new ReactStylesDiffMap(JavaOnlyMap.of(keysAndValues)); - } - - @Test - public void testValueWithMaxValue() { - ReactSlider view = mManager.createViewInstance(mThemedContext); - - mManager.updateProperties(view, buildStyles("maximumValue", 10.0)); - mManager.updateProperties(view, buildStyles("value", 5.5)); - assertThat(view.getProgress()).isEqualTo(70); - } - - @Test - public void testValueWithMaxValueSetBeforeMinValue() { - ReactSlider view = mManager.createViewInstance(mThemedContext); - - mManager.updateProperties(view, buildStyles("maximumValue", 10.0)); - mManager.updateProperties(view, buildStyles("minimumValue", 5.0)); - mManager.updateProperties(view, buildStyles("value", 5.5)); - assertThat(view.getProgress()).isEqualTo(13); - } - - @Test - public void testValueWithMinValueSetBeforeMaxValue() { - ReactSlider view = mManager.createViewInstance(mThemedContext); - - mManager.updateProperties(view, buildStyles("minimumValue", 5.0)); - mManager.updateProperties(view, buildStyles("maximumValue", 10.0)); - mManager.updateProperties(view, buildStyles("value", 5.5)); - assertThat(view.getProgress()).isEqualTo(13); - } - - @Test - public void testValueWithMaxValueAndStep() { - ReactSlider view = mManager.createViewInstance(mThemedContext); - - mManager.updateProperties(view, buildStyles("maximumValue", 10.0)); - mManager.updateProperties(view, buildStyles("step", 3.0)); - mManager.updateProperties(view, buildStyles("value", 5.5)); - assertThat(view.getProgress()).isEqualTo(2); - } - - @Test - public void testValueWithMaxValueAndMinValueAndStep() { - ReactSlider view = mManager.createViewInstance(mThemedContext); - - mManager.updateProperties(view, buildStyles("maximumValue", 10.0)); - mManager.updateProperties(view, buildStyles("minimumValue", 5.0)); - mManager.updateProperties(view, buildStyles("step", 3.0)); - mManager.updateProperties(view, buildStyles("value", 10.0)); - assertThat(view.getProgress()).isEqualTo(2); - } -} diff --git a/ReactCommon/react/renderer/components/slider/BUCK b/ReactCommon/react/renderer/components/slider/BUCK deleted file mode 100644 index 7cc3f2f6849f02..00000000000000 --- a/ReactCommon/react/renderer/components/slider/BUCK +++ /dev/null @@ -1,117 +0,0 @@ -load( - "//tools/build_defs/oss:rn_defs.bzl", - "ANDROID", - "APPLE", - "CXX", - "YOGA_CXX_TARGET", - "fb_xplat_cxx_test", - "get_apple_compiler_flags", - "get_apple_inspector_flags", - "get_preprocessor_flags_for_build_mode", - "react_native_target", - "react_native_xplat_target", - "rn_xplat_cxx_library", - "subdir_glob", -) - -APPLE_COMPILER_FLAGS = get_apple_compiler_flags() - -rn_xplat_cxx_library( - name = "slider", - srcs = glob( - ["**/*.cpp"], - exclude = glob([ - "tests/**/*.cpp", - "platform/**/*.cpp", - ]), - ), - headers = [], - header_namespace = "", - exported_headers = subdir_glob( - [ - ("", "*.h"), - ], - prefix = "react/renderer/components/slider", - ), - compiler_flags_pedantic = True, - cxx_tests = [":tests"], - fbandroid_deps = [ - "//xplat/folly:dynamic", - react_native_target("jni/react/jni:jni"), - react_native_xplat_target("react/renderer/mapbuffer:mapbuffer"), - ], - fbandroid_exported_headers = subdir_glob( - [ - ("", "*.h"), - ("platform/android/react/renderer/components/slider", "*.h"), - ], - prefix = "react/renderer/components/slider", - ), - fbandroid_headers = glob( - ["platform/android/react/renderer/components/slider/*.h"], - ), - fbandroid_srcs = glob( - ["platform/android/react/renderer/components/slider/*.cpp"], - ), - fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, - fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), - force_static = True, - ios_exported_headers = subdir_glob( - [ - ("", "*.h"), - ("platform/ios", "*.h"), - ], - prefix = "react/renderer/components/slider", - ), - ios_headers = glob( - ["platform/ios/*.h"], - ), - ios_srcs = glob( - ["platform/ios/*.cpp"], - ), - labels = [ - "pfh:ReactNative_CommonInfrastructurePlaceholder", - ], - platforms = (ANDROID, APPLE, CXX), - preprocessor_flags = [ - "-DLOG_TAG=\"ReactNative\"", - "-DWITH_FBSYSTRACE=1", - ], - visibility = ["PUBLIC"], - deps = [ - YOGA_CXX_TARGET, - react_native_xplat_target("react/debug:debug"), - react_native_xplat_target("react/renderer/debug:debug"), - react_native_xplat_target("react/renderer/core:core"), - react_native_xplat_target("react/renderer/components/image:image"), - react_native_xplat_target("react/renderer/components/view:view"), - react_native_xplat_target("react/renderer/graphics:graphics"), - react_native_xplat_target("react/renderer/imagemanager:imagemanager"), - react_native_xplat_target("react/renderer/uimanager:uimanager"), - react_native_xplat_target("react/renderer/componentregistry:componentregistry"), - "//xplat/js/react-native-github:generated_components-rncore", - ], -) - -fb_xplat_cxx_test( - name = "tests", - srcs = glob(["tests/**/*.cpp"]), - headers = glob(["tests/**/*.h"]), - compiler_flags = [ - "-fexceptions", - "-frtti", - "-std=c++17", - "-Wall", - ], - contacts = ["oncall+react_native@xmail.facebook.com"], - platforms = ( - # `Apple` and `Android` flavors are disabled because the module (built with those flavors) requires Emulator/Simulator (which is expensive and slow). At the same time, we don't really have tests here. - # ANDROID, - # APPLE, - CXX, - ), - deps = [ - ":slider", - "//xplat/third-party/gmock:gtest", - ], -) diff --git a/ReactCommon/react/renderer/components/slider/CMakeLists.txt b/ReactCommon/react/renderer/components/slider/CMakeLists.txt deleted file mode 100644 index e69b5146b92ea9..00000000000000 --- a/ReactCommon/react/renderer/components/slider/CMakeLists.txt +++ /dev/null @@ -1,45 +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. - -cmake_minimum_required(VERSION 3.13) -set(CMAKE_VERBOSE_MAKEFILE on) - -add_compile_options( - -fexceptions - -frtti - -std=c++17 - -Wall - -Wpedantic - -Wno-gnu-zero-variadic-macro-arguments - -DLOG_TAG=\"Fabric\") - -file(GLOB rrc_slider_SRC CONFIGURE_DEPENDS *.cpp platform/android/react/renderer/components/slider/*.cpp) -add_library(rrc_slider STATIC ${rrc_slider_SRC}) - -target_include_directories(rrc_slider - PUBLIC - ${REACT_COMMON_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/platform/android/ -) - -target_link_libraries(rrc_slider - glog - fbjni - folly_runtime - glog_init - react_codegen_rncore - react_debug - react_render_componentregistry - react_render_core - react_render_debug - react_render_graphics - react_render_imagemanager - react_render_mapbuffer - react_render_uimanager - reactnativejni - rrc_image - rrc_view - yoga -) diff --git a/ReactCommon/react/renderer/components/slider/SliderComponentDescriptor.h b/ReactCommon/react/renderer/components/slider/SliderComponentDescriptor.h deleted file mode 100644 index 8a4d592c3ff0dd..00000000000000 --- a/ReactCommon/react/renderer/components/slider/SliderComponentDescriptor.h +++ /dev/null @@ -1,58 +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. - */ - -#pragma once - -#include -#include -#include - -namespace facebook { -namespace react { - -/* - * Descriptor for component. - */ -class SliderComponentDescriptor final - : public ConcreteComponentDescriptor { - public: - SliderComponentDescriptor(ComponentDescriptorParameters const ¶meters) - : ConcreteComponentDescriptor(parameters), - imageManager_(std::make_shared(contextContainer_)), - measurementsManager_( - SliderMeasurementsManager::shouldMeasureSlider() - ? std::make_shared(contextContainer_) - : nullptr) {} - - void adopt(ShadowNode::Unshared const &shadowNode) const override { - ConcreteComponentDescriptor::adopt(shadowNode); - - auto sliderShadowNode = - std::static_pointer_cast(shadowNode); - - // `SliderShadowNode` uses `ImageManager` to initiate image loading and - // communicate the loading state and results to mounting layer. - sliderShadowNode->setImageManager(imageManager_); - - if (measurementsManager_) { - // `SliderShadowNode` uses `SliderMeasurementsManager` to - // provide measurements to Yoga. - sliderShadowNode->setSliderMeasurementsManager(measurementsManager_); - - // All `SliderShadowNode`s must have leaf Yoga nodes with properly - // setup measure function. - sliderShadowNode->enableMeasurement(); - } - } - - private: - const SharedImageManager imageManager_; - const std::shared_ptr measurementsManager_; -}; - -} // namespace react -} // namespace facebook diff --git a/ReactCommon/react/renderer/components/slider/SliderShadowNode.cpp b/ReactCommon/react/renderer/components/slider/SliderShadowNode.cpp deleted file mode 100644 index bb70718bf54b6d..00000000000000 --- a/ReactCommon/react/renderer/components/slider/SliderShadowNode.cpp +++ /dev/null @@ -1,100 +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. - */ - -#include "SliderShadowNode.h" - -#include - -namespace facebook::react { - -extern const char SliderComponentName[] = "Slider"; - -void SliderShadowNode::setImageManager(const SharedImageManager &imageManager) { - ensureUnsealed(); - imageManager_ = imageManager; -} - -void SliderShadowNode::setSliderMeasurementsManager( - const std::shared_ptr &measurementsManager) { - ensureUnsealed(); - measurementsManager_ = measurementsManager; -} - -void SliderShadowNode::updateStateIfNeeded() { - const auto &newTrackImageSource = getTrackImageSource(); - const auto &newMinimumTrackImageSource = getMinimumTrackImageSource(); - const auto &newMaximumTrackImageSource = getMaximumTrackImageSource(); - const auto &newThumbImageSource = getThumbImageSource(); - - auto const ¤tState = getStateData(); - - auto trackImageSource = currentState.getTrackImageSource(); - auto minimumTrackImageSource = currentState.getMinimumTrackImageSource(); - auto maximumTrackImageSource = currentState.getMaximumTrackImageSource(); - auto thumbImageSource = currentState.getThumbImageSource(); - - bool anyChanged = newTrackImageSource != trackImageSource || - newMinimumTrackImageSource != minimumTrackImageSource || - newMaximumTrackImageSource != maximumTrackImageSource || - newThumbImageSource != thumbImageSource; - - if (!anyChanged) { - return; - } - - // Now we are about to mutate the Shadow Node. - ensureUnsealed(); - - // It is not possible to copy or move image requests from SliderLocalData, - // so instead we recreate any image requests (that may already be in-flight?) - // TODO: check if multiple requests are cached or if it's a net loss - auto state = SliderState{ - newTrackImageSource, - imageManager_->requestImage(newTrackImageSource, getSurfaceId()), - newMinimumTrackImageSource, - imageManager_->requestImage(newMinimumTrackImageSource, getSurfaceId()), - newMaximumTrackImageSource, - imageManager_->requestImage(newMaximumTrackImageSource, getSurfaceId()), - newThumbImageSource, - imageManager_->requestImage(newThumbImageSource, getSurfaceId())}; - setStateData(std::move(state)); -} - -ImageSource SliderShadowNode::getTrackImageSource() const { - return getConcreteProps().trackImage; -} - -ImageSource SliderShadowNode::getMinimumTrackImageSource() const { - return getConcreteProps().minimumTrackImage; -} - -ImageSource SliderShadowNode::getMaximumTrackImageSource() const { - return getConcreteProps().maximumTrackImage; -} - -ImageSource SliderShadowNode::getThumbImageSource() const { - return getConcreteProps().thumbImage; -} - -#pragma mark - LayoutableShadowNode - -Size SliderShadowNode::measureContent( - LayoutContext const & /*layoutContext*/, - LayoutConstraints const &layoutConstraints) const { - if (SliderMeasurementsManager::shouldMeasureSlider()) { - return measurementsManager_->measure(getSurfaceId(), layoutConstraints); - } - - return {}; -} - -void SliderShadowNode::layout(LayoutContext layoutContext) { - updateStateIfNeeded(); - ConcreteViewShadowNode::layout(layoutContext); -} - -} // namespace facebook::react diff --git a/ReactCommon/react/renderer/components/slider/SliderShadowNode.h b/ReactCommon/react/renderer/components/slider/SliderShadowNode.h deleted file mode 100644 index b1aa0dc9c5fc90..00000000000000 --- a/ReactCommon/react/renderer/components/slider/SliderShadowNode.h +++ /dev/null @@ -1,77 +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. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace facebook { -namespace react { - -extern const char SliderComponentName[]; - -/* - * `ShadowNode` for component. - */ -class SliderShadowNode final : public ConcreteViewShadowNode< - SliderComponentName, - SliderProps, - SliderEventEmitter, - SliderState> { - public: - using ConcreteViewShadowNode::ConcreteViewShadowNode; - - // Associates a shared `ImageManager` with the node. - void setImageManager(const SharedImageManager &imageManager); - - // Associates a shared `SliderMeasurementsManager` with the node. - void setSliderMeasurementsManager( - const std::shared_ptr &measurementsManager); - - static SliderState initialStateData( - ShadowNodeFragment const &fragment, - ShadowNodeFamilyFragment const &familyFragment, - ComponentDescriptor const &componentDescriptor) { - auto imageSource = ImageSource{ImageSource::Type::Invalid}; - return { - imageSource, - {imageSource, nullptr}, - imageSource, - {imageSource, nullptr}, - imageSource, - {imageSource, nullptr}, - imageSource, - {imageSource, nullptr}}; - } - -#pragma mark - LayoutableShadowNode - - Size measureContent( - LayoutContext const &layoutContext, - LayoutConstraints const &layoutConstraints) const override; - void layout(LayoutContext layoutContext) override; - - private: - void updateStateIfNeeded(); - - ImageSource getTrackImageSource() const; - ImageSource getMinimumTrackImageSource() const; - ImageSource getMaximumTrackImageSource() const; - ImageSource getThumbImageSource() const; - - SharedImageManager imageManager_; - std::shared_ptr measurementsManager_; -}; - -} // namespace react -} // namespace facebook diff --git a/ReactCommon/react/renderer/components/slider/SliderState.cpp b/ReactCommon/react/renderer/components/slider/SliderState.cpp deleted file mode 100644 index adce049789dfb9..00000000000000 --- a/ReactCommon/react/renderer/components/slider/SliderState.cpp +++ /dev/null @@ -1,44 +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. - */ - -#include "SliderState.h" - -namespace facebook::react { - -ImageSource SliderState::getTrackImageSource() const { - return trackImageSource_; -} - -ImageRequest const &SliderState::getTrackImageRequest() const { - return *trackImageRequest_; -} - -ImageSource SliderState::getMinimumTrackImageSource() const { - return minimumTrackImageSource_; -} - -ImageRequest const &SliderState::getMinimumTrackImageRequest() const { - return *minimumTrackImageRequest_; -} - -ImageSource SliderState::getMaximumTrackImageSource() const { - return maximumTrackImageSource_; -} - -ImageRequest const &SliderState::getMaximumTrackImageRequest() const { - return *maximumTrackImageRequest_; -} - -ImageSource SliderState::getThumbImageSource() const { - return thumbImageSource_; -} - -ImageRequest const &SliderState::getThumbImageRequest() const { - return *thumbImageRequest_; -} - -} // namespace facebook::react diff --git a/ReactCommon/react/renderer/components/slider/SliderState.h b/ReactCommon/react/renderer/components/slider/SliderState.h deleted file mode 100644 index 7984a657088ab9..00000000000000 --- a/ReactCommon/react/renderer/components/slider/SliderState.h +++ /dev/null @@ -1,89 +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. - */ - -#pragma once - -#ifdef ANDROID -#include -#include -#include -#endif - -#include -#include - -namespace facebook { -namespace react { - -/* - * State for component. - */ -class SliderState final { - public: - SliderState( - ImageSource const &trackImageSource, - ImageRequest trackImageRequest, - ImageSource const &minimumTrackImageSource, - ImageRequest minimumTrackImageRequest, - ImageSource const &maximumTrackImageSource, - ImageRequest maximumTrackImageRequest, - ImageSource const &thumbImageSource, - ImageRequest thumbImageRequest) - : trackImageSource_(trackImageSource), - trackImageRequest_( - std::make_shared(std::move(trackImageRequest))), - minimumTrackImageSource_(minimumTrackImageSource), - minimumTrackImageRequest_(std::make_shared( - std::move(minimumTrackImageRequest))), - maximumTrackImageSource_(maximumTrackImageSource), - maximumTrackImageRequest_(std::make_shared( - std::move(maximumTrackImageRequest))), - thumbImageSource_(thumbImageSource), - thumbImageRequest_( - std::make_shared(std::move(thumbImageRequest))){}; - - SliderState() = default; - - ImageSource getTrackImageSource() const; - ImageRequest const &getTrackImageRequest() const; - - ImageSource getMinimumTrackImageSource() const; - ImageRequest const &getMinimumTrackImageRequest() const; - - ImageSource getMaximumTrackImageSource() const; - ImageRequest const &getMaximumTrackImageRequest() const; - - ImageSource getThumbImageSource() const; - ImageRequest const &getThumbImageRequest() const; - -#ifdef ANDROID - SliderState(SliderState const &previousState, folly::dynamic data){}; - - /* - * Empty implementation for Android because it doesn't use this class. - */ - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; -#endif - - private: - ImageSource trackImageSource_; - std::shared_ptr trackImageRequest_; - ImageSource minimumTrackImageSource_; - std::shared_ptr minimumTrackImageRequest_; - ImageSource maximumTrackImageSource_; - std::shared_ptr maximumTrackImageRequest_; - ImageSource thumbImageSource_; - std::shared_ptr thumbImageRequest_; -}; - -} // namespace react -} // namespace facebook diff --git a/ReactCommon/react/renderer/components/slider/platform/android/react/renderer/components/slider/SliderMeasurementsManager.cpp b/ReactCommon/react/renderer/components/slider/platform/android/react/renderer/components/slider/SliderMeasurementsManager.cpp deleted file mode 100644 index 2f161fec5c0701..00000000000000 --- a/ReactCommon/react/renderer/components/slider/platform/android/react/renderer/components/slider/SliderMeasurementsManager.cpp +++ /dev/null @@ -1,72 +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. - */ - -#include "SliderMeasurementsManager.h" - -#include -#include -#include - -using namespace facebook::jni; - -namespace facebook::react { - -Size SliderMeasurementsManager::measure( - SurfaceId surfaceId, - LayoutConstraints layoutConstraints) const { - { - std::lock_guard lock(mutex_); - if (hasBeenMeasured_) { - return cachedMeasurement_; - } - } - - const jni::global_ref &fabricUIManager = - contextContainer_->at>("FabricUIManager"); - - static auto measure = - jni::findClassStatic("com/facebook/react/fabric/FabricUIManager") - ->getMethod("measure"); - - auto minimumSize = layoutConstraints.minimumSize; - auto maximumSize = layoutConstraints.maximumSize; - - local_ref componentName = make_jstring("RCTSlider"); - - auto measurement = yogaMeassureToSize(measure( - fabricUIManager, - surfaceId, - componentName.get(), - nullptr, - nullptr, - nullptr, - minimumSize.width, - maximumSize.width, - minimumSize.height, - maximumSize.height)); - - // Explicitly release smart pointers to free up space faster in JNI tables - componentName.reset(); - - { - std::lock_guard lock(mutex_); - cachedMeasurement_ = measurement; - } - - return measurement; -} - -} // namespace facebook::react diff --git a/ReactCommon/react/renderer/components/slider/platform/android/react/renderer/components/slider/SliderMeasurementsManager.h b/ReactCommon/react/renderer/components/slider/platform/android/react/renderer/components/slider/SliderMeasurementsManager.h deleted file mode 100644 index a8234ae6aea366..00000000000000 --- a/ReactCommon/react/renderer/components/slider/platform/android/react/renderer/components/slider/SliderMeasurementsManager.h +++ /dev/null @@ -1,40 +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. - */ - -#pragma once - -#include -#include -#include - -namespace facebook { -namespace react { - -/** - * Class that manages slider measurements across platforms. - * On iOS it is a noop, since the height is passed in from JS on iOS only. - */ -class SliderMeasurementsManager { - public: - SliderMeasurementsManager(const ContextContainer::Shared &contextContainer) - : contextContainer_(contextContainer) {} - - static inline bool shouldMeasureSlider() { - return true; - } - - Size measure(SurfaceId surfaceId, LayoutConstraints layoutConstraints) const; - - private: - const ContextContainer::Shared contextContainer_; - mutable std::mutex mutex_; - mutable bool hasBeenMeasured_ = false; - mutable Size cachedMeasurement_{}; -}; - -} // namespace react -} // namespace facebook diff --git a/ReactCommon/react/renderer/components/slider/platform/ios/SliderMeasurementsManager.cpp b/ReactCommon/react/renderer/components/slider/platform/ios/SliderMeasurementsManager.cpp deleted file mode 100644 index 773d3f7bbeec35..00000000000000 --- a/ReactCommon/react/renderer/components/slider/platform/ios/SliderMeasurementsManager.cpp +++ /dev/null @@ -1,23 +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. - */ - -#include "SliderMeasurementsManager.h" - -#include - -namespace facebook { -namespace react { - -Size SliderMeasurementsManager::measure( - SurfaceId surfaceId, - LayoutConstraints layoutConstraints) const { - react_native_assert(false); // should never reach this point - return {}; -} - -} // namespace react -} // namespace facebook diff --git a/ReactCommon/react/renderer/components/slider/platform/ios/SliderMeasurementsManager.h b/ReactCommon/react/renderer/components/slider/platform/ios/SliderMeasurementsManager.h deleted file mode 100644 index 067deeadff5b5c..00000000000000 --- a/ReactCommon/react/renderer/components/slider/platform/ios/SliderMeasurementsManager.h +++ /dev/null @@ -1,33 +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. - */ - -#pragma once - -#include -#include -#include - -namespace facebook { -namespace react { - -/** - * Class that manages slider measurements across platforms. - * On iOS it is a noop, since the height is passed in from JS on iOS only. - */ -class SliderMeasurementsManager { - public: - SliderMeasurementsManager(ContextContainer::Shared const &contextContainer) {} - - static inline bool shouldMeasureSlider() { - return false; - } - - Size measure(SurfaceId surfaceId, LayoutConstraints layoutConstraints) const; -}; - -} // namespace react -} // namespace facebook diff --git a/ReactCommon/react/renderer/components/slider/tests/SliderTest.cpp b/ReactCommon/react/renderer/components/slider/tests/SliderTest.cpp deleted file mode 100644 index 5bb020e65b714a..00000000000000 --- a/ReactCommon/react/renderer/components/slider/tests/SliderTest.cpp +++ /dev/null @@ -1,14 +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. - */ - -#include - -#include - -TEST(SliderTest, testSomething) { - // TODO -}