forked from react-native-masked-view/masked-view
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-native-masked-view#162): fabric support
- add JS Flow spec - make android viewmanager to conform to codegen-ed specs - add codegen-ed spec to make viewmanager work also in old arch - use install_module_dependencies in the podspec to install deps on both new and old architectures - add subclass of RCTViewComponentView - use fabric implementation when RCT_NEW_ARCH_ENABLED flag is true - set RN peerDependency to be version >= 0.71
- Loading branch information
1 parent
40ff01d
commit 8843834
Showing
12 changed files
with
221 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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 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
24 changes: 15 additions & 9 deletions
24
android/src/main/java/org/reactnative/maskedview/RNCMaskedViewManager.java
This file contains 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
34 changes: 25 additions & 9 deletions
34
android/src/main/java/org/reactnative/maskedview/RNCMaskedViewPackage.java
This file contains 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 |
---|---|---|
@@ -1,25 +1,41 @@ | ||
package org.reactnative.maskedview; | ||
|
||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.bridge.JavaScriptModule; | ||
import androidx.annotation.Nullable; | ||
|
||
import com.facebook.react.TurboReactPackage; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.module.model.ReactModuleInfo; | ||
import com.facebook.react.module.model.ReactModuleInfoProvider; | ||
import com.facebook.react.uimanager.ViewManager; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class RNCMaskedViewPackage extends TurboReactPackage { | ||
@Override | ||
@Nullable | ||
public NativeModule getModule(String name, ReactApplicationContext reactContext) { | ||
return null; | ||
} | ||
|
||
public class RNCMaskedViewPackage implements ReactPackage { | ||
@Override | ||
public List<NativeModule> createNativeModules(ReactApplicationContext reactApplicationContext) { | ||
return Collections.emptyList(); | ||
public ReactModuleInfoProvider getReactModuleInfoProvider() { | ||
final Map<String, ReactModuleInfo> reactModuleInfoMap = new HashMap<>(); | ||
return new ReactModuleInfoProvider() { | ||
@Override | ||
public Map<String, ReactModuleInfo> getReactModuleInfos() { | ||
return reactModuleInfoMap; | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public List<ViewManager> createViewManagers(ReactApplicationContext reactApplicationContext) { | ||
return Arrays.<ViewManager>asList( | ||
new RNCMaskedViewManager() | ||
); | ||
return Arrays.<ViewManager>asList( | ||
new RNCMaskedViewManager() | ||
); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
android/src/oldarch/java/com/facebook/react/viewmanagers/RNCMaskedViewManagerDelegate.java
This file contains 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,31 @@ | ||
/** | ||
* 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.BaseViewManagerDelegate; | ||
import com.facebook.react.uimanager.BaseViewManagerInterface; | ||
|
||
public class RNCMaskedViewManagerDelegate<T extends View, U extends BaseViewManagerInterface<T> & RNCMaskedViewManagerInterface<T>> extends BaseViewManagerDelegate<T, U> { | ||
public RNCMaskedViewManagerDelegate(U viewManager) { | ||
super(viewManager); | ||
} | ||
@Override | ||
public void setProperty(T view, String propName, @Nullable Object value) { | ||
switch (propName) { | ||
case "androidRenderingMode": | ||
mViewManager.setAndroidRenderingMode(view, (String) value); | ||
break; | ||
default: | ||
super.setProperty(view, propName, value); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
android/src/oldarch/java/com/facebook/react/viewmanagers/RNCMaskedViewManagerInterface.java
This file contains 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 androidx.annotation.Nullable; | ||
|
||
public interface RNCMaskedViewManagerInterface<T extends View> { | ||
void setAndroidRenderingMode(T view, @Nullable String value); | ||
} |
This file contains 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,7 @@ | ||
#if RCT_NEW_ARCH_ENABLED | ||
#import <React/RCTViewComponentView.h> | ||
|
||
@interface RNCMaskedViewComponentView : RCTViewComponentView | ||
|
||
@end | ||
#endif |
This file contains 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,66 @@ | ||
#if RCT_NEW_ARCH_ENABLED | ||
#import "RNCMaskedViewComponentView.h" | ||
|
||
#import <React/RCTConversions.h> | ||
#import <RCTTypeSafety/RCTConvertHelpers.h> | ||
|
||
#import <react/renderer/components/RNMaskedViewSpec/ComponentDescriptors.h> | ||
#import <react/renderer/components/RNMaskedViewSpec/EventEmitters.h> | ||
#import <react/renderer/components/RNMaskedViewSpec/Props.h> | ||
#import <react/renderer/components/RNMaskedViewSpec/RCTComponentViewHelpers.h> | ||
|
||
#import "RCTFabricComponentsPlugins.h" | ||
|
||
using namespace facebook::react; | ||
|
||
@interface RNCMaskedViewComponentView () <RCTRNCMaskedViewViewProtocol> | ||
@end | ||
|
||
@implementation RNCMaskedViewComponentView | ||
|
||
- (instancetype)initWithFrame:(CGRect)frame | ||
{ | ||
if (self = [super initWithFrame:frame]) { | ||
static const auto defaultProps = std::make_shared<const RNCMaskedViewProps>(); | ||
_props = defaultProps; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index | ||
{ | ||
if (index == 0) { | ||
self.maskView = childComponentView; | ||
return; | ||
} | ||
[self addSubview:childComponentView]; | ||
} | ||
|
||
- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index | ||
{ | ||
if (index == 0) { | ||
self.maskView = nil; | ||
return; | ||
} | ||
[childComponentView removeFromSuperview]; | ||
} | ||
|
||
- (void)invalidateLayer | ||
{ | ||
// RCTViewComponentView uses invalidateLayer to do border rendering. | ||
// We don't need to do that in RNCMaskedViewComponentView, so we | ||
// stub this method and override the default implementation. | ||
} | ||
|
||
+ (ComponentDescriptorProvider)componentDescriptorProvider | ||
{ | ||
return concreteComponentDescriptorProvider<RNCMaskedViewComponentDescriptor>(); | ||
} | ||
|
||
@end | ||
|
||
Class<RCTComponentViewProtocol> RNCMaskedViewCls(void) | ||
{ | ||
return RNCMaskedViewComponentView.class; | ||
} | ||
#endif |
This file contains 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 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 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,22 @@ | ||
/** | ||
* @flow strict-local | ||
* @format | ||
*/ | ||
|
||
import type {ViewProps} from 'react-native/Libraries/Components/View/ViewPropTypes'; | ||
import type {HostComponent} from 'react-native/Libraries/Renderer/shims/ReactNativeTypes'; | ||
import type {WithDefault} from 'react-native/Libraries/Types/CodegenTypes'; | ||
|
||
import * as React from 'react'; | ||
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; | ||
|
||
type NativeProps = $ReadOnly<{ | ||
...ViewProps, | ||
|
||
//Props | ||
androidRenderingMode?: WithDefault<'hardware' | 'software', 'hardware'>, | ||
}>; | ||
|
||
export default (codegenNativeComponent<NativeProps>( | ||
'RNCMaskedView', | ||
): HostComponent<NativeProps>); |
This file contains 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