aix 0.1.0-alpha.1 → 0.2.0

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.
Files changed (50) hide show
  1. package/ios/HybridAix.swift +22 -8
  2. package/lib/commonjs/aix.js +11 -0
  3. package/lib/commonjs/aix.js.map +1 -1
  4. package/lib/commonjs/hooks/useContentInsetHandler.js +30 -0
  5. package/lib/commonjs/hooks/useContentInsetHandler.js.map +1 -0
  6. package/lib/commonjs/index.js +9 -1
  7. package/lib/commonjs/index.js.map +1 -1
  8. package/lib/module/aix.js +11 -0
  9. package/lib/module/aix.js.map +1 -1
  10. package/lib/module/hooks/useContentInsetHandler.js +26 -0
  11. package/lib/module/hooks/useContentInsetHandler.js.map +1 -0
  12. package/lib/module/index.js +1 -0
  13. package/lib/module/index.js.map +1 -1
  14. package/lib/typescript/src/aix.d.ts +7 -3
  15. package/lib/typescript/src/aix.d.ts.map +1 -1
  16. package/lib/typescript/src/hooks/useContentInsetHandler.d.ts +21 -0
  17. package/lib/typescript/src/hooks/useContentInsetHandler.d.ts.map +1 -0
  18. package/lib/typescript/src/index.d.ts +2 -0
  19. package/lib/typescript/src/index.d.ts.map +1 -1
  20. package/lib/typescript/src/views/aix.nitro.d.ts +30 -0
  21. package/lib/typescript/src/views/aix.nitro.d.ts.map +1 -1
  22. package/nitrogen/generated/android/AixOnLoad.cpp +2 -0
  23. package/nitrogen/generated/android/c++/JAixContentInsets.hpp +69 -0
  24. package/nitrogen/generated/android/c++/JFunc_void_AixContentInsets.hpp +78 -0
  25. package/nitrogen/generated/android/c++/JHybridAixSpec.cpp +33 -0
  26. package/nitrogen/generated/android/c++/JHybridAixSpec.hpp +4 -0
  27. package/nitrogen/generated/android/c++/views/JHybridAixStateUpdater.cpp +8 -0
  28. package/nitrogen/generated/android/kotlin/com/margelo/nitro/aix/AixContentInsets.kt +47 -0
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/aix/Func_void_AixContentInsets.kt +80 -0
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/aix/HybridAixSpec.kt +20 -0
  31. package/nitrogen/generated/ios/Aix-Swift-Cxx-Bridge.cpp +8 -0
  32. package/nitrogen/generated/ios/Aix-Swift-Cxx-Bridge.hpp +41 -0
  33. package/nitrogen/generated/ios/Aix-Swift-Cxx-Umbrella.hpp +4 -0
  34. package/nitrogen/generated/ios/c++/HybridAixSpecSwift.hpp +18 -0
  35. package/nitrogen/generated/ios/c++/views/HybridAixComponent.mm +10 -0
  36. package/nitrogen/generated/ios/swift/AixContentInsets.swift +117 -0
  37. package/nitrogen/generated/ios/swift/Func_void_AixContentInsets.swift +47 -0
  38. package/nitrogen/generated/ios/swift/HybridAixSpec.swift +2 -0
  39. package/nitrogen/generated/ios/swift/HybridAixSpec_cxx.swift +56 -0
  40. package/nitrogen/generated/shared/c++/AixContentInsets.hpp +87 -0
  41. package/nitrogen/generated/shared/c++/HybridAixSpec.cpp +4 -0
  42. package/nitrogen/generated/shared/c++/HybridAixSpec.hpp +8 -0
  43. package/nitrogen/generated/shared/c++/views/HybridAixComponent.cpp +24 -0
  44. package/nitrogen/generated/shared/c++/views/HybridAixComponent.hpp +4 -1
  45. package/nitrogen/generated/shared/json/AixConfig.json +2 -0
  46. package/package.json +4 -2
  47. package/src/aix.tsx +26 -11
  48. package/src/hooks/useContentInsetHandler.ts +28 -0
  49. package/src/index.ts +2 -0
  50. package/src/views/aix.nitro.ts +10 -0
@@ -19,12 +19,16 @@ namespace margelo::nitro::aix { struct AixScrollOnFooterSizeUpdate; }
19
19
  namespace margelo::nitro::aix { struct AixAdditionalContentInsetsProp; }
20
20
  // Forward declaration of `AixScrollIndicatorInsets` to properly resolve imports.
21
21
  namespace margelo::nitro::aix { struct AixScrollIndicatorInsets; }
22
+ // Forward declaration of `AixContentInsets` to properly resolve imports.
23
+ namespace margelo::nitro::aix { struct AixContentInsets; }
22
24
 
23
25
  #include "AixScrollOnFooterSizeUpdate.hpp"
24
26
  #include <optional>
25
27
  #include "AixAdditionalContentInsetsProp.hpp"
26
28
  #include "AixScrollIndicatorInsets.hpp"
27
29
  #include <string>
30
+ #include "AixContentInsets.hpp"
31
+ #include <functional>
28
32
 
29
33
  namespace margelo::nitro::aix {
30
34
 
@@ -67,6 +71,10 @@ namespace margelo::nitro::aix {
67
71
  virtual void setMainScrollViewID(const std::optional<std::string>& mainScrollViewID) = 0;
68
72
  virtual std::optional<double> getPenultimateCellIndex() = 0;
69
73
  virtual void setPenultimateCellIndex(std::optional<double> penultimateCellIndex) = 0;
74
+ virtual std::optional<bool> getShouldApplyContentInsets() = 0;
75
+ virtual void setShouldApplyContentInsets(std::optional<bool> shouldApplyContentInsets) = 0;
76
+ virtual std::optional<std::function<void(const AixContentInsets& /* insets */)>> getOnWillApplyContentInsets() = 0;
77
+ virtual void setOnWillApplyContentInsets(const std::optional<std::function<void(const AixContentInsets& /* insets */)>>& onWillApplyContentInsets) = 0;
70
78
 
71
79
  public:
72
80
  // Methods
@@ -95,6 +95,26 @@ namespace margelo::nitro::aix::views {
95
95
  throw std::runtime_error(std::string("Aix.penultimateCellIndex: ") + exc.what());
96
96
  }
97
97
  }()),
98
+ shouldApplyContentInsets([&]() -> CachedProp<std::optional<bool>> {
99
+ try {
100
+ const react::RawValue* rawValue = rawProps.at("shouldApplyContentInsets", nullptr, nullptr);
101
+ if (rawValue == nullptr) return sourceProps.shouldApplyContentInsets;
102
+ const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
103
+ return CachedProp<std::optional<bool>>::fromRawValue(*runtime, value, sourceProps.shouldApplyContentInsets);
104
+ } catch (const std::exception& exc) {
105
+ throw std::runtime_error(std::string("Aix.shouldApplyContentInsets: ") + exc.what());
106
+ }
107
+ }()),
108
+ onWillApplyContentInsets([&]() -> CachedProp<std::optional<std::function<void(const AixContentInsets& /* insets */)>>> {
109
+ try {
110
+ const react::RawValue* rawValue = rawProps.at("onWillApplyContentInsets", nullptr, nullptr);
111
+ if (rawValue == nullptr) return sourceProps.onWillApplyContentInsets;
112
+ const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
113
+ return CachedProp<std::optional<std::function<void(const AixContentInsets& /* insets */)>>>::fromRawValue(*runtime, value.asObject(*runtime).getProperty(*runtime, "f"), sourceProps.onWillApplyContentInsets);
114
+ } catch (const std::exception& exc) {
115
+ throw std::runtime_error(std::string("Aix.onWillApplyContentInsets: ") + exc.what());
116
+ }
117
+ }()),
98
118
  hybridRef([&]() -> CachedProp<std::optional<std::function<void(const std::shared_ptr<HybridAixSpec>& /* ref */)>>> {
99
119
  try {
100
120
  const react::RawValue* rawValue = rawProps.at("hybridRef", nullptr, nullptr);
@@ -115,6 +135,8 @@ namespace margelo::nitro::aix::views {
115
135
  additionalScrollIndicatorInsets(other.additionalScrollIndicatorInsets),
116
136
  mainScrollViewID(other.mainScrollViewID),
117
137
  penultimateCellIndex(other.penultimateCellIndex),
138
+ shouldApplyContentInsets(other.shouldApplyContentInsets),
139
+ onWillApplyContentInsets(other.onWillApplyContentInsets),
118
140
  hybridRef(other.hybridRef) { }
119
141
 
120
142
  bool HybridAixProps::filterObjectKeys(const std::string& propName) {
@@ -126,6 +148,8 @@ namespace margelo::nitro::aix::views {
126
148
  case hashString("additionalScrollIndicatorInsets"): return true;
127
149
  case hashString("mainScrollViewID"): return true;
128
150
  case hashString("penultimateCellIndex"): return true;
151
+ case hashString("shouldApplyContentInsets"): return true;
152
+ case hashString("onWillApplyContentInsets"): return true;
129
153
  case hashString("hybridRef"): return true;
130
154
  default: return false;
131
155
  }
@@ -21,9 +21,10 @@
21
21
  #include "AixAdditionalContentInsetsProp.hpp"
22
22
  #include "AixScrollIndicatorInsets.hpp"
23
23
  #include <string>
24
+ #include "AixContentInsets.hpp"
25
+ #include <functional>
24
26
  #include <memory>
25
27
  #include "HybridAixSpec.hpp"
26
- #include <functional>
27
28
 
28
29
  namespace margelo::nitro::aix::views {
29
30
 
@@ -53,6 +54,8 @@ namespace margelo::nitro::aix::views {
53
54
  CachedProp<std::optional<AixScrollIndicatorInsets>> additionalScrollIndicatorInsets;
54
55
  CachedProp<std::optional<std::string>> mainScrollViewID;
55
56
  CachedProp<std::optional<double>> penultimateCellIndex;
57
+ CachedProp<std::optional<bool>> shouldApplyContentInsets;
58
+ CachedProp<std::optional<std::function<void(const AixContentInsets& /* insets */)>>> onWillApplyContentInsets;
56
59
  CachedProp<std::optional<std::function<void(const std::shared_ptr<HybridAixSpec>& /* ref */)>>> hybridRef;
57
60
 
58
61
  private:
@@ -11,6 +11,8 @@
11
11
  "additionalScrollIndicatorInsets": true,
12
12
  "mainScrollViewID": true,
13
13
  "penultimateCellIndex": true,
14
+ "shouldApplyContentInsets": true,
15
+ "onWillApplyContentInsets": true,
14
16
  "hybridRef": true
15
17
  }
16
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aix",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.2.0",
4
4
  "author": "Fernando Rojo",
5
5
  "repository": {
6
6
  "type": "git",
@@ -19,6 +19,7 @@
19
19
  "react-native": "0.82",
20
20
  "react-native-builder-bob": "^0.37.0",
21
21
  "react-native-nitro-modules": "0.31.10",
22
+ "react-native-reanimated": "^3.17.0",
22
23
  "conventional-changelog-conventionalcommits": "^9.1.0",
23
24
  "semantic-release": "^24.2.9",
24
25
  "typescript": "^5.8.3"
@@ -26,7 +27,8 @@
26
27
  "peerDependencies": {
27
28
  "react": "*",
28
29
  "react-native": "*",
29
- "react-native-nitro-modules": "*"
30
+ "react-native-nitro-modules": "*",
31
+ "react-native-reanimated": ">=3.0.0"
30
32
  },
31
33
  "bugs": "https://github.com/vercel/aix/issues",
32
34
  "description": "aix is a react native package built with Nitro",
package/src/aix.tsx CHANGED
@@ -4,17 +4,26 @@ import {
4
4
  type HybridRef,
5
5
  } from 'react-native-nitro-modules'
6
6
  import AixConfig from '../nitrogen/generated/shared/json/AixConfig.json'
7
- import type { AixProps, AixMethods } from './views/aix.nitro'
8
- import { forwardRef } from 'react'
7
+ import type { AixProps, AixMethods, AixContentInsets } from './views/aix.nitro'
8
+ import { forwardRef, type ComponentProps } from 'react'
9
+ import Animated from 'react-native-reanimated'
9
10
 
10
11
  export type AixRef = HybridRef<AixProps, AixMethods>
11
12
 
12
- const AixInternal = getHostComponent<AixProps, AixMethods>(
13
+ const AixInternal = Animated.createAnimatedComponent(getHostComponent<AixProps, AixMethods>(
13
14
  'Aix',
14
15
  () => AixConfig
15
- )
16
+ ))
17
+
18
+ // User-facing props type that accepts regular functions (not wrapped callbacks)
19
+ type AixComponentProps = Omit<
20
+ ComponentProps<typeof AixInternal>,
21
+ 'onWillApplyContentInsets' | 'hybridRef'
22
+ > & {
23
+ onWillApplyContentInsets?: (insets: AixContentInsets) => void
24
+ }
16
25
 
17
- export const Aix = forwardRef<AixRef, React.ComponentProps<typeof AixInternal>>(
26
+ export const Aix = forwardRef<AixRef, AixComponentProps>(
18
27
  function Aix(props, ref) {
19
28
  return (
20
29
  <AixInternal
@@ -26,15 +35,21 @@ export const Aix = forwardRef<AixRef, React.ComponentProps<typeof AixInternal>>(
26
35
  animated: false,
27
36
  }
28
37
  }
38
+ // Wrap onWillApplyContentInsets with callback() if provided
39
+ onWillApplyContentInsets={
40
+ props.onWillApplyContentInsets
41
+ ? callback(props.onWillApplyContentInsets)
42
+ : undefined
43
+ }
29
44
  hybridRef={
30
45
  ref
31
46
  ? callback((r) => {
32
- if (typeof ref === 'function') {
33
- ref(r)
34
- } else {
35
- ref.current = r
36
- }
37
- })
47
+ if (typeof ref === 'function') {
48
+ ref(r)
49
+ } else {
50
+ ref.current = r
51
+ }
52
+ })
38
53
  : undefined
39
54
  }
40
55
  />
@@ -0,0 +1,28 @@
1
+ import { useCallback } from 'react'
2
+ import type { AixContentInsets } from '../views/aix.nitro'
3
+
4
+ /**
5
+ * Hook that creates a stable callback handler for content inset updates.
6
+ * Use this with `onWillApplyContentInsets` prop to receive inset updates.
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * const bottomInset = useSharedValue<number | null>(null)
11
+ *
12
+ * const contentInsetHandler = useContentInsetHandler((insets) => {
13
+ * bottomInset.value = insets.bottom ?? null
14
+ * })
15
+ *
16
+ * <Aix
17
+ * shouldApplyContentInsets={false}
18
+ * onWillApplyContentInsets={contentInsetHandler}
19
+ * />
20
+ * ```
21
+ */
22
+ export function useContentInsetHandler(
23
+ handler: (insets: AixContentInsets) => void,
24
+ dependencies: unknown[] = []
25
+ ) {
26
+ // eslint-disable-next-line react-hooks/exhaustive-deps
27
+ return useCallback(handler, dependencies)
28
+ }
package/src/index.ts CHANGED
@@ -7,6 +7,8 @@ export * from './fade-in'
7
7
 
8
8
  export { Aix, type AixRef } from './aix'
9
9
  export { AixFooter } from './footer'
10
+ export { useContentInsetHandler } from './hooks/useContentInsetHandler'
11
+ export type { AixContentInsets } from './views/aix.nitro'
10
12
 
11
13
  export const AixCell = getHostComponent<AixCellViewProps, {}>(
12
14
  'AixCellView',
@@ -45,6 +45,13 @@ export interface AixScrollOnFooterSizeUpdate {
45
45
  animated?: boolean
46
46
  }
47
47
 
48
+ export interface AixContentInsets {
49
+ top?: number
50
+ left?: number
51
+ bottom?: number
52
+ right?: number
53
+ }
54
+
48
55
  export interface AixProps extends HybridViewProps {
49
56
  shouldStartAtEnd: boolean
50
57
  /**
@@ -111,6 +118,9 @@ export interface AixProps extends HybridViewProps {
111
118
  *
112
119
  */
113
120
  penultimateCellIndex?: number
121
+
122
+ shouldApplyContentInsets?: boolean
123
+ onWillApplyContentInsets?: (insets: AixContentInsets) => void
114
124
  }
115
125
 
116
126
  export interface AixMethods extends HybridViewMethods {