@sdcx/bottom-sheet 1.0.6 → 1.0.8

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.
@@ -1,10 +1,15 @@
1
1
  package com.reactnative.bottomsheet;
2
2
 
3
3
  import android.content.Context;
4
+ import android.graphics.PixelFormat;
5
+ import android.graphics.drawable.Drawable;
6
+
7
+ import androidx.annotation.NonNull;
4
8
 
5
9
  import com.facebook.react.bridge.Arguments;
6
10
  import com.facebook.react.bridge.WritableMap;
7
11
  import com.facebook.react.uimanager.PixelUtil;
12
+ import com.facebook.react.uimanager.PointerEvents;
8
13
  import com.facebook.react.uimanager.StateWrapper;
9
14
  import com.facebook.react.views.view.ReactViewGroup;
10
15
 
@@ -14,7 +19,6 @@ import com.facebook.react.views.view.ReactViewGroup;
14
19
  */
15
20
  public class BottomSheetContentView extends ReactViewGroup {
16
21
 
17
- @SuppressWarnings("NullableProblems")
18
22
  private StateWrapper stateWrapper;
19
23
 
20
24
  public BottomSheetContentView(Context context) {
@@ -36,4 +40,14 @@ public class BottomSheetContentView extends ReactViewGroup {
36
40
  stateWrapper.updateState(map);
37
41
  }
38
42
  }
43
+
44
+ @NonNull
45
+ @Override
46
+ public PointerEvents getPointerEvents() {
47
+ Drawable bg = getBackground();
48
+ if (bg == null || bg.getOpacity() != PixelFormat.OPAQUE) {
49
+ return PointerEvents.BOX_NONE;
50
+ }
51
+ return PointerEvents.AUTO;
52
+ }
39
53
  }
@@ -0,0 +1,18 @@
1
+ #pragma once
2
+
3
+ #include <react/renderer/components/bottomsheet/BottomSheetContentViewShadowNode.h>
4
+ #include <react/renderer/core/ConcreteComponentDescriptor.h>
5
+
6
+ namespace facebook {
7
+ namespace react {
8
+
9
+ /*
10
+ * Descriptor for <BottomSheetContentView> component.
11
+ */
12
+ class BottomSheetContentViewComponentDescriptor final
13
+ : public ConcreteComponentDescriptor<BottomSheetContentViewShadowNode> {
14
+ using ConcreteComponentDescriptor::ConcreteComponentDescriptor;
15
+ };
16
+
17
+ } // namespace react
18
+ } // namespace facebook
@@ -0,0 +1,19 @@
1
+ #include "BottomSheetContentViewShadowNode.h"
2
+
3
+ namespace facebook {
4
+ namespace react {
5
+
6
+ extern const char BottomSheetContentViewComponentName[] = "BottomSheetContentView";
7
+
8
+ Point BottomSheetContentViewShadowNode::getContentOriginOffset(bool includeTransform) const {
9
+ auto stateData = getStateData();
10
+ auto contentOffset = stateData.contentOffset;
11
+
12
+ return {
13
+ .x = 0,
14
+ .y = static_cast<Float>(contentOffset),
15
+ };
16
+ }
17
+
18
+ } // namespace react
19
+ } // namespace facebook
@@ -0,0 +1,32 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+ #include <react/renderer/components/bottomsheet/BottomSheetContentViewState.h>
5
+ #include <react/renderer/components/bottomsheet/EventEmitters.h>
6
+ #include <react/renderer/components/bottomsheet/Props.h>
7
+ #include <react/renderer/components/view/ConcreteViewShadowNode.h>
8
+
9
+ namespace facebook {
10
+ namespace react {
11
+
12
+ JSI_EXPORT extern const char BottomSheetContentViewComponentName[];
13
+
14
+ /*
15
+ * ShadowNode for <BottomSheetContentView>. getContentOriginOffset returns
16
+ * the view's top offset so that RN hit-testing uses the correct coordinates
17
+ * when the parent BottomSheet has moved this content view.
18
+ */
19
+ class JSI_EXPORT BottomSheetContentViewShadowNode final
20
+ : public ConcreteViewShadowNode<
21
+ BottomSheetContentViewComponentName,
22
+ BottomSheetContentViewProps,
23
+ ViewEventEmitter,
24
+ BottomSheetContentViewState> {
25
+ using ConcreteViewShadowNode::ConcreteViewShadowNode;
26
+
27
+ public:
28
+ Point getContentOriginOffset(bool includeTransform) const override;
29
+ };
30
+
31
+ } // namespace react
32
+ } // namespace facebook
@@ -0,0 +1,15 @@
1
+ #include "BottomSheetContentViewState.h"
2
+
3
+ namespace facebook {
4
+ namespace react {
5
+
6
+ #ifdef ANDROID
7
+ folly::dynamic BottomSheetContentViewState::getDynamic() const {
8
+ folly::dynamic data = folly::dynamic::object();
9
+ data["contentOffset"] = contentOffset;
10
+ return data;
11
+ }
12
+ #endif
13
+
14
+ } // namespace react
15
+ } // namespace facebook
@@ -0,0 +1,42 @@
1
+ #pragma once
2
+
3
+ #include <react/renderer/components/bottomsheet/Props.h>
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 {
12
+ namespace react {
13
+
14
+ /*
15
+ * State for <BottomSheetContentView> component. contentOffset is the offset
16
+ * (actual top - layout top) of this view. Used by getContentOriginOffset
17
+ * so that hit-testing uses the correct content origin when the sheet moves the view.
18
+ */
19
+ class JSI_EXPORT BottomSheetContentViewState final {
20
+ public:
21
+ using Shared = std::shared_ptr<const BottomSheetContentViewState>;
22
+
23
+ BottomSheetContentViewState() = default;
24
+
25
+ #ifdef ANDROID
26
+ BottomSheetContentViewState(
27
+ BottomSheetContentViewState const &previousState,
28
+ folly::dynamic data) {
29
+ contentOffset = data.getDefault("contentOffset", previousState.contentOffset).asDouble();
30
+ }
31
+ #endif
32
+
33
+ double contentOffset{};
34
+
35
+ #ifdef ANDROID
36
+ folly::dynamic getDynamic() const;
37
+ MapBuffer getMapBuffer() const { return MapBufferBuilder::EMPTY(); }
38
+ #endif
39
+ };
40
+
41
+ } // namespace react
42
+ } // namespace facebook
@@ -1,5 +1,8 @@
1
1
  #import "RNBottomSheetContentView.h"
2
2
 
3
+ #import <CoreGraphics/CoreGraphics.h>
4
+ #import <UIKit/UIKit.h>
5
+
3
6
  #import <react/renderer/components/bottomsheet/BottomSheetContentViewComponentDescriptor.h>
4
7
  #import <react/renderer/components/bottomsheet/BottomSheetContentViewShadowNode.h>
5
8
  #import <react/renderer/components/bottomsheet/EventEmitters.h>
@@ -44,4 +47,20 @@ using namespace facebook::react;
44
47
  });
45
48
  }
46
49
 
50
+ - (BOOL)_isBackgroundTransparent {
51
+ if (self.backgroundColor == nil) {
52
+ return YES;
53
+ }
54
+ return CGColorGetAlpha(self.backgroundColor.CGColor) < 1.0;
55
+ }
56
+
57
+ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
58
+ UIView *hit = [super hitTest:point withEvent:event];
59
+ // 背景透明时相当于 BOX_NONE:只有子视图接收触摸,自身不接收
60
+ if ([self _isBackgroundTransparent] && hit == self) {
61
+ return nil;
62
+ }
63
+ return hit;
64
+ }
65
+
47
66
  @end
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sdcx/bottom-sheet",
3
3
  "description": "A react-native BottomSheet component.",
4
- "version": "1.0.6",
4
+ "version": "1.0.8",
5
5
  "main": "./dist/index",
6
6
  "module": "./dist/index",
7
7
  "types": "./dist/index.d.ts",
@@ -13,6 +13,7 @@
13
13
  "dist",
14
14
  "android",
15
15
  "ios",
16
+ "common",
16
17
  "react-native.config.js",
17
18
  "RNBottomSheet.podspec",
18
19
  "!android/build",