@lodev09/react-native-true-sheet 3.0.0-beta.5 → 3.0.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewController.kt +25 -3
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewManager.kt +1 -2
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContainerViewComponentDescriptor.h +24 -0
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContainerViewShadowNode.cpp +46 -0
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContainerViewShadowNode.h +28 -0
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContainerViewState.cpp +11 -0
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContainerViewState.h +42 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
|
|
|
4
4
|
import android.graphics.Color
|
|
5
5
|
import android.graphics.drawable.ShapeDrawable
|
|
6
6
|
import android.graphics.drawable.shapes.RoundRectShape
|
|
7
|
+
import android.util.TypedValue
|
|
7
8
|
import android.view.MotionEvent
|
|
8
9
|
import android.view.View
|
|
9
10
|
import android.view.WindowManager
|
|
@@ -194,8 +195,8 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
|
|
|
194
195
|
}
|
|
195
196
|
}
|
|
196
197
|
|
|
197
|
-
var cornerRadius: Float =
|
|
198
|
-
var sheetBackgroundColor: Int =
|
|
198
|
+
var cornerRadius: Float = 28f.dpToPx()
|
|
199
|
+
var sheetBackgroundColor: Int = 0
|
|
199
200
|
var detents = mutableListOf(0.5, 1.0)
|
|
200
201
|
|
|
201
202
|
private var windowAnimation: Int = 0
|
|
@@ -205,6 +206,24 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
|
|
|
205
206
|
jSPointerDispatcher = JSPointerDispatcher(this)
|
|
206
207
|
}
|
|
207
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Get the default background color from Material Design 3 theme.
|
|
211
|
+
* Uses colorSurfaceContainerLow which adapts to light/dark mode.
|
|
212
|
+
*/
|
|
213
|
+
fun getDefaultBackgroundColor(): Int {
|
|
214
|
+
val typedValue = TypedValue()
|
|
215
|
+
return if (reactContext.theme.resolveAttribute(
|
|
216
|
+
com.google.android.material.R.attr.colorSurfaceContainerLow,
|
|
217
|
+
typedValue,
|
|
218
|
+
true
|
|
219
|
+
)
|
|
220
|
+
) {
|
|
221
|
+
typedValue.data
|
|
222
|
+
} else {
|
|
223
|
+
Color.WHITE
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
208
227
|
// ==================== Lifecycle ====================
|
|
209
228
|
|
|
210
229
|
/**
|
|
@@ -497,8 +516,11 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
|
|
|
497
516
|
0f
|
|
498
517
|
)
|
|
499
518
|
|
|
519
|
+
// 0 (transparent) is used as sentinel for "use system default"
|
|
520
|
+
val backgroundColor = if (sheetBackgroundColor != 0) sheetBackgroundColor else getDefaultBackgroundColor()
|
|
521
|
+
|
|
500
522
|
val background = ShapeDrawable(RoundRectShape(outerRadii, null, null))
|
|
501
|
-
background.paint.color =
|
|
523
|
+
background.paint.color = backgroundColor
|
|
502
524
|
|
|
503
525
|
this.background = background
|
|
504
526
|
this.clipToOutline = true
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
package com.lodev09.truesheet
|
|
2
2
|
|
|
3
|
-
import android.graphics.Color
|
|
4
3
|
import android.view.WindowManager
|
|
5
4
|
import com.facebook.react.bridge.ReadableArray
|
|
6
5
|
import com.facebook.react.module.annotations.ReactModule
|
|
@@ -84,7 +83,7 @@ class TrueSheetViewManager :
|
|
|
84
83
|
view.setDetents(detents)
|
|
85
84
|
}
|
|
86
85
|
|
|
87
|
-
@ReactProp(name = "background", defaultInt =
|
|
86
|
+
@ReactProp(name = "background", defaultInt = 0)
|
|
88
87
|
override fun setBackground(view: TrueSheetView, color: Int) {
|
|
89
88
|
view.setSheetBackgroundColor(color)
|
|
90
89
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <react/renderer/components/TrueSheetSpec/TrueSheetContainerViewShadowNode.h>
|
|
4
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
5
|
+
|
|
6
|
+
namespace facebook::react {
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Descriptor for <TrueSheetContainerView> component.
|
|
10
|
+
*/
|
|
11
|
+
class TrueSheetContainerViewComponentDescriptor final
|
|
12
|
+
: public ConcreteComponentDescriptor<TrueSheetContainerViewShadowNode> {
|
|
13
|
+
using ConcreteComponentDescriptor::ConcreteComponentDescriptor;
|
|
14
|
+
|
|
15
|
+
void adopt(ShadowNode &shadowNode) const override {
|
|
16
|
+
auto &concreteShadowNode =
|
|
17
|
+
static_cast<TrueSheetContainerViewShadowNode &>(shadowNode);
|
|
18
|
+
concreteShadowNode.adjustLayoutWithState();
|
|
19
|
+
|
|
20
|
+
ConcreteComponentDescriptor::adopt(shadowNode);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
} // namespace facebook::react
|
package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContainerViewShadowNode.cpp
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#include "TrueSheetContainerViewShadowNode.h"
|
|
2
|
+
|
|
3
|
+
#include <yoga/style/StyleSizeLength.h>
|
|
4
|
+
|
|
5
|
+
namespace facebook::react {
|
|
6
|
+
|
|
7
|
+
extern const char TrueSheetContainerViewComponentName[] = "TrueSheetContainerView";
|
|
8
|
+
|
|
9
|
+
void TrueSheetContainerViewShadowNode::adjustLayoutWithState() {
|
|
10
|
+
ensureUnsealed();
|
|
11
|
+
|
|
12
|
+
auto state = std::static_pointer_cast<
|
|
13
|
+
const TrueSheetContainerViewShadowNode::ConcreteState>(getState());
|
|
14
|
+
auto stateData = state->getData();
|
|
15
|
+
|
|
16
|
+
// If container dimensions are set from native, override Yoga's dimensions
|
|
17
|
+
if (stateData.containerWidth > 0 || stateData.containerHeight > 0) {
|
|
18
|
+
auto &props = getConcreteProps();
|
|
19
|
+
yoga::Style adjustedStyle = props.yogaStyle;
|
|
20
|
+
auto currentStyle = yogaNode_.style();
|
|
21
|
+
bool needsUpdate = false;
|
|
22
|
+
|
|
23
|
+
// Set width if provided
|
|
24
|
+
if (stateData.containerWidth > 0) {
|
|
25
|
+
adjustedStyle.setDimension(yoga::Dimension::Width, yoga::StyleSizeLength::points(stateData.containerWidth));
|
|
26
|
+
if (adjustedStyle.dimension(yoga::Dimension::Width) != currentStyle.dimension(yoga::Dimension::Width)) {
|
|
27
|
+
needsUpdate = true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Set height if provided
|
|
32
|
+
if (stateData.containerHeight > 0) {
|
|
33
|
+
adjustedStyle.setDimension(yoga::Dimension::Height, yoga::StyleSizeLength::points(stateData.containerHeight));
|
|
34
|
+
if (adjustedStyle.dimension(yoga::Dimension::Height) != currentStyle.dimension(yoga::Dimension::Height)) {
|
|
35
|
+
needsUpdate = true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (needsUpdate) {
|
|
40
|
+
yogaNode_.setStyle(adjustedStyle);
|
|
41
|
+
yogaNode_.setDirty(true);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
#include <react/renderer/components/TrueSheetSpec/EventEmitters.h>
|
|
5
|
+
#include <react/renderer/components/TrueSheetSpec/Props.h>
|
|
6
|
+
#include <react/renderer/components/TrueSheetSpec/TrueSheetContainerViewState.h>
|
|
7
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
8
|
+
|
|
9
|
+
namespace facebook::react {
|
|
10
|
+
|
|
11
|
+
JSI_EXPORT extern const char TrueSheetContainerViewComponentName[];
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
* `ShadowNode` for <TrueSheetContainerView> component.
|
|
15
|
+
*/
|
|
16
|
+
class JSI_EXPORT TrueSheetContainerViewShadowNode final
|
|
17
|
+
: public ConcreteViewShadowNode<
|
|
18
|
+
TrueSheetContainerViewComponentName,
|
|
19
|
+
TrueSheetContainerViewProps,
|
|
20
|
+
TrueSheetContainerViewEventEmitter,
|
|
21
|
+
TrueSheetContainerViewState> {
|
|
22
|
+
using ConcreteViewShadowNode::ConcreteViewShadowNode;
|
|
23
|
+
|
|
24
|
+
public:
|
|
25
|
+
void adjustLayoutWithState();
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#include "TrueSheetContainerViewState.h"
|
|
2
|
+
|
|
3
|
+
namespace facebook::react {
|
|
4
|
+
|
|
5
|
+
#ifdef ANDROID
|
|
6
|
+
folly::dynamic TrueSheetContainerViewState::getDynamic() const {
|
|
7
|
+
return folly::dynamic::object("containerWidth", containerWidth)("containerHeight", containerHeight);
|
|
8
|
+
}
|
|
9
|
+
#endif
|
|
10
|
+
|
|
11
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
|
|
5
|
+
#ifdef ANDROID
|
|
6
|
+
#include <folly/dynamic.h>
|
|
7
|
+
#include <react/renderer/mapbuffer/MapBuffer.h>
|
|
8
|
+
#include <react/renderer/mapbuffer/MapBufferBuilder.h>
|
|
9
|
+
#endif
|
|
10
|
+
|
|
11
|
+
namespace facebook::react {
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
* State for <TrueSheetContainerView> component.
|
|
15
|
+
* Contains the container dimensions from native.
|
|
16
|
+
*/
|
|
17
|
+
class TrueSheetContainerViewState final {
|
|
18
|
+
public:
|
|
19
|
+
using Shared = std::shared_ptr<const TrueSheetContainerViewState>;
|
|
20
|
+
|
|
21
|
+
TrueSheetContainerViewState() = default;
|
|
22
|
+
|
|
23
|
+
#ifdef ANDROID
|
|
24
|
+
TrueSheetContainerViewState(
|
|
25
|
+
TrueSheetContainerViewState const &previousState,
|
|
26
|
+
folly::dynamic data)
|
|
27
|
+
: containerWidth(static_cast<float>(data["containerWidth"].getDouble())),
|
|
28
|
+
containerHeight(static_cast<float>(data["containerHeight"].getDouble())) {}
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
float containerWidth{0};
|
|
32
|
+
float containerHeight{0};
|
|
33
|
+
|
|
34
|
+
#ifdef ANDROID
|
|
35
|
+
folly::dynamic getDynamic() const;
|
|
36
|
+
MapBuffer getMapBuffer() const {
|
|
37
|
+
return MapBufferBuilder::EMPTY();
|
|
38
|
+
}
|
|
39
|
+
#endif
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
} // namespace facebook::react
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lodev09/react-native-true-sheet",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.6",
|
|
4
4
|
"description": "The true native bottom sheet experience for your React Native Apps.",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./lib/module/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"lib",
|
|
19
19
|
"android",
|
|
20
20
|
"ios",
|
|
21
|
-
"
|
|
21
|
+
"common",
|
|
22
22
|
"*.podspec",
|
|
23
23
|
"react-native.config.js",
|
|
24
24
|
"!ios/build",
|