-
-
Notifications
You must be signed in to change notification settings - Fork 604
feat: Add ContentScrollViewDetector component #3463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kmichalikk
wants to merge
10
commits into
main
Choose a base branch
from
@kmichalikk/scroll-view-hosting-component
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+266
−1
Open
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9d9e8b1
Add native component
kmichalikk e7755c9
Implement native component for android fabric
kmichalikk 763aaa8
Add paper classes for android
kmichalikk 44a6faa
Add paper classes for iOS
kmichalikk acc54a4
Implement searching and registration, rename components
kmichalikk f3276e1
Undo implementation & testing
kmichalikk 1f616c1
Remove android log
kmichalikk 374b9ab
Run spotlessApply
kmichalikk d152c66
Add review suggestions
kmichalikk 8be2ef9
Rename findContentScrollView
kmichalikk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
android/src/main/java/com/swmansion/rnscreens/ContentScrollViewDetector.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.swmansion.rnscreens | ||
|
|
||
| import android.annotation.SuppressLint | ||
| import com.facebook.react.bridge.ReactContext | ||
| import com.facebook.react.views.view.ReactViewGroup | ||
|
|
||
| @SuppressLint("ViewConstructor") | ||
| class ContentScrollViewDetector( | ||
| val reactContext: ReactContext, | ||
| ) : ReactViewGroup(reactContext) { | ||
| override fun onAttachedToWindow() { | ||
| super.onAttachedToWindow() | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
android/src/main/java/com/swmansion/rnscreens/ContentScrollViewDetectorViewManager.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package com.swmansion.rnscreens | ||
|
|
||
| import com.facebook.react.module.annotations.ReactModule | ||
| import com.facebook.react.uimanager.ThemedReactContext | ||
| import com.facebook.react.uimanager.ViewGroupManager | ||
| import com.facebook.react.uimanager.ViewManagerDelegate | ||
| import com.facebook.react.viewmanagers.RNSContentScrollViewDetectorManagerDelegate | ||
| import com.facebook.react.viewmanagers.RNSContentScrollViewDetectorManagerInterface | ||
|
|
||
| @ReactModule(name = ContentScrollViewDetectorViewManager.REACT_CLASS) | ||
| open class ContentScrollViewDetectorViewManager : | ||
| ViewGroupManager<ContentScrollViewDetector>(), | ||
| RNSContentScrollViewDetectorManagerInterface<ContentScrollViewDetector> { | ||
| private val delegate: ViewManagerDelegate<ContentScrollViewDetector> | ||
|
|
||
| init { | ||
| delegate = | ||
| RNSContentScrollViewDetectorManagerDelegate<ContentScrollViewDetector, ContentScrollViewDetectorViewManager>( | ||
| this, | ||
| ) | ||
| } | ||
|
|
||
| override fun getName() = REACT_CLASS | ||
|
|
||
| override fun createViewInstance(reactContext: ThemedReactContext) = ContentScrollViewDetector(reactContext) | ||
|
|
||
| override fun getDelegate(): ViewManagerDelegate<ContentScrollViewDetector> = delegate | ||
|
|
||
| companion object Companion { | ||
| const val REACT_CLASS = "RNSContentScrollViewDetector" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...per/java/com/facebook/react/viewmanagers/RNSContentScrollViewDetectorManagerDelegate.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /** | ||
| * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). | ||
| * | ||
| * Do not edit this file as changes may cause incorrect behavior and will be lost | ||
| * once the code is regenerated. | ||
| * | ||
| * @generated by codegen project: GeneratePropsJavaDelegate.js | ||
| */ | ||
|
|
||
| package com.facebook.react.viewmanagers; | ||
|
|
||
| import android.view.View; | ||
| import androidx.annotation.Nullable; | ||
| import com.facebook.react.uimanager.BaseViewManager; | ||
| import com.facebook.react.uimanager.BaseViewManagerDelegate; | ||
| import com.facebook.react.uimanager.LayoutShadowNode; | ||
|
|
||
| @SuppressWarnings("deprecation") | ||
| public class RNSContentScrollViewDetectorManagerDelegate<T extends View, U extends BaseViewManager<T, ? extends LayoutShadowNode> & RNSContentScrollViewDetectorManagerInterface<T>> extends BaseViewManagerDelegate<T, U> { | ||
| public RNSContentScrollViewDetectorManagerDelegate(U viewManager) { | ||
| super(viewManager); | ||
| } | ||
| @Override | ||
| public void setProperty(T view, String propName, @Nullable Object value) { | ||
| super.setProperty(view, propName, value); | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
...er/java/com/facebook/react/viewmanagers/RNSContentScrollViewDetectorManagerInterface.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /** | ||
| * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). | ||
| * | ||
| * Do not edit this file as changes may cause incorrect behavior and will be lost | ||
| * once the code is regenerated. | ||
| * | ||
| * @generated by codegen project: GeneratePropsJavaInterface.js | ||
| */ | ||
|
|
||
| package com.facebook.react.viewmanagers; | ||
|
|
||
| import android.view.View; | ||
| import com.facebook.react.uimanager.ViewManagerWithGeneratedInterface; | ||
|
|
||
| public interface RNSContentScrollViewDetectorManagerInterface<T extends View> extends ViewManagerWithGeneratedInterface { | ||
| // No props | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #pragma once | ||
|
|
||
| #import "ContentScrollViewConsumer.h" | ||
| #import "RNSReactBaseView.h" | ||
| #import "RNSScrollViewFinder.h" | ||
|
|
||
| #if !RCT_NEW_ARCH_ENABLED | ||
| #import <React/RCTViewManager.h> | ||
| #endif // !RCT_NEW_ARCH_ENABLED | ||
|
|
||
| NS_ASSUME_NONNULL_BEGIN | ||
|
|
||
| @interface RNSContentScrollViewDetector : | ||
| #ifdef RCT_NEW_ARCH_ENABLED | ||
| RCTViewComponentView | ||
| #else | ||
| UIView | ||
| #endif | ||
|
|
||
| - (UIScrollView *)findContentScrollView; | ||
kmichalikk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - (void)registerContentScrollViewInHierarchy; | ||
kmichalikk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - (void)unregisterContentScrollViewInHierarchy; | ||
|
|
||
| @end | ||
|
|
||
| #if !RCT_NEW_ARCH_ENABLED | ||
|
|
||
| @interface RNSContentScrollViewDetectorViewManager : RCTViewManager | ||
| @end | ||
|
|
||
| #endif // !RCT_NEW_ARCH_ENABLED | ||
|
|
||
| NS_ASSUME_NONNULL_END | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| #import "RNSContentScrollViewDetector.h" | ||
| #import <React/RCTLog.h> | ||
| #import <react/renderer/components/rnscreens/ComponentDescriptors.h> | ||
|
|
||
| namespace react = facebook::react; | ||
|
|
||
| @implementation RNSContentScrollViewDetector { | ||
| UIScrollView *_scrollView; | ||
| UIView *_linkedView; | ||
kmichalikk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| - (void)didMoveToWindow | ||
| { | ||
| if (self.window == nil) { | ||
| [self unregisterContentScrollViewInHierarchy]; | ||
kmichalikk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } else { | ||
| if ((_scrollView = [self findContentScrollView])) { | ||
| [self registerContentScrollViewInHierarchy]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| - (UIScrollView *)findContentScrollView | ||
| { | ||
| auto scrollView = [RNSScrollViewFinder findScrollViewInFirstDescendantChainFrom:self]; | ||
| if (scrollView) { | ||
| RCTLogInfo(@"Found content ScrollView"); | ||
| return scrollView; | ||
| } | ||
|
|
||
| return nullptr; | ||
| } | ||
|
|
||
| - (void)registerContentScrollViewInHierarchy | ||
| { | ||
| if (_linkedView != nullptr) { | ||
| RCTLogWarn( | ||
| @"Content ScrollView has already been registered. Make sure to only have one ScrollViewWrapper for content ScrollView."); | ||
| [self unregisterContentScrollViewInHierarchy]; | ||
| } | ||
|
|
||
| UIView *parent = self.superview; | ||
| while (parent) { | ||
| if ([parent respondsToSelector:@selector(findContentScrollView)]) { | ||
kmichalikk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| RCTLogWarn( | ||
| @"Nested ScrollViewWrapper detected. Make sure to only have one ScrollViewWrapper for content ScrollView."); | ||
| } | ||
|
|
||
| if ([parent respondsToSelector:@selector(registerContentScrollView:)]) { | ||
| [(id<ContentScrollViewConsumer>)parent registerContentScrollView:_scrollView]; | ||
t0maboro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| _linkedView = parent; | ||
| RCTLogInfo(@"registered content ScrollView for: %@", parent); | ||
| break; | ||
| } | ||
|
|
||
| parent = parent.superview; | ||
| } | ||
| } | ||
|
|
||
| - (void)unregisterContentScrollViewInHierarchy | ||
| { | ||
| if (_linkedView == nullptr) { | ||
| return; | ||
| } | ||
|
|
||
| [(id<ContentScrollViewConsumer>)_linkedView unregisterContentScrollView:_scrollView]; | ||
|
|
||
| RCTLogInfo(@"unregistered content ScrollView for: %@", _linkedView); | ||
| _linkedView = nullptr; | ||
| } | ||
|
|
||
| #pragma mark - RCTViewComponentViewProtocol | ||
|
|
||
| + (react::ComponentDescriptorProvider)componentDescriptorProvider | ||
| { | ||
| return react::concreteComponentDescriptorProvider<react::RNSContentScrollViewDetectorComponentDescriptor>(); | ||
| } | ||
|
|
||
| @end | ||
|
|
||
| #if RCT_NEW_ARCH_ENABLED | ||
| Class<RCTComponentViewProtocol> RNSContentScrollViewDetectorCls(void) | ||
| { | ||
| return RNSContentScrollViewDetector.class; | ||
| } | ||
| #endif // RCT_NEW_ARCH_ENABLED | ||
|
|
||
| #if !RCT_NEW_ARCH_ENABLED | ||
|
|
||
| @implementation RNSContentScrollViewDetectorViewManager | ||
|
|
||
| RCT_EXPORT_MODULE(RNSContentScrollViewDetector); | ||
|
|
||
| - (UIView *)view | ||
| { | ||
| return [[RNSContentScrollViewDetector alloc] init]; | ||
| } | ||
|
|
||
| @end | ||
|
|
||
| #endif // !RCT_NEW_ARCH_ENABLED | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #pragma once | ||
|
|
||
| @protocol ContentScrollViewConsumer | ||
|
|
||
| - (void)registerContentScrollView:(UIScrollView *)scrollView; | ||
|
|
||
| - (void)unregisterContentScrollView:(UIScrollView *)scrollView; | ||
|
|
||
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| 'use client'; | ||
|
|
||
| import React from 'react'; | ||
| import ContentScrollViewDetectorNativeComponent from '../fabric/ContentScrollViewDetectorNativeComponent'; | ||
|
|
||
| function ContentScrollViewDetector({ | ||
| children, | ||
| }: { | ||
| children?: React.ReactNode; | ||
| }) { | ||
| return ( | ||
| <ContentScrollViewDetectorNativeComponent> | ||
| {children} | ||
| </ContentScrollViewDetectorNativeComponent> | ||
| ); | ||
| } | ||
|
|
||
| export default ContentScrollViewDetector; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { codegenNativeComponent } from 'react-native'; | ||
| import type { ViewProps } from 'react-native'; | ||
|
|
||
| export interface NativeProps extends ViewProps {} | ||
|
|
||
| export default codegenNativeComponent<NativeProps>( | ||
| 'RNSContentScrollViewDetector', | ||
| {}, | ||
| ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.