Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
ENV['RCT_NEW_ARCH_ENABLED'] = "1"

platform :ios, min_ios_version_supported
prepare_react_native_project!
Expand Down
36 changes: 36 additions & 0 deletions ios/FabricLookComponent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// FabricLookComponent.swift
// react-native-fabric-look
//
// Created by Yusuf Zeren on 20.05.2023.
//

import UIKit

@objc(FabricLookComponent)
public class FabricLookComponent: UIView {


@objc public var color: String = "" {
didSet {
self.backgroundColor = hexStringToUIColor(hexColor: color)
}
}


func hexStringToUIColor(hexColor: String) -> UIColor {
let stringScanner = Scanner(string: hexColor)

if(hexColor.hasPrefix("#")) {
stringScanner.scanLocation = 1
}
var color: UInt32 = 0
stringScanner.scanHexInt32(&color)

let r = CGFloat(Int(color >> 16) & 0x000000FF)
let g = CGFloat(Int(color >> 8) & 0x000000FF)
let b = CGFloat(Int(color) & 0x000000FF)

return UIColor(red: r / 255.0, green: g / 255.0, blue: b / 255.0, alpha: 1)
}
}
1 change: 1 addition & 0 deletions ios/FabricLookView.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#ifdef RCT_NEW_ARCH_ENABLED
#import <React/RCTViewComponentView.h>
#import <UIKit/UIKit.h>
#import <React/RCTViewManager.h>

#ifndef FabricLookViewNativeComponent_h
#define FabricLookViewNativeComponent_h
Expand Down
19 changes: 14 additions & 5 deletions ios/FabricLookView.mm
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#ifdef RCT_NEW_ARCH_ENABLED
#import "FabricLookView.h"

#import <React/RCTConversions.h>
#import <RCTTypeSafety/RCTConvertHelpers.h>


#import <react/renderer/components/RNFabricLookViewSpec/ComponentDescriptors.h>
#import <react/renderer/components/RNFabricLookViewSpec/EventEmitters.h>
#import <react/renderer/components/RNFabricLookViewSpec/Props.h>
#import <react/renderer/components/RNFabricLookViewSpec/RCTComponentViewHelpers.h>

#import "RCTFabricComponentsPlugins.h"
#import "Utils.h"
#import "react-native-fabric-look-Swift.h"

using namespace facebook::react;

Expand All @@ -16,9 +20,15 @@ @interface FabricLookView () <RCTFabricLookViewViewProtocol>
@end

@implementation FabricLookView {
UIView * _view;
FabricLookComponent * _view;
}

+ (BOOL)requiresMainQueueSetup
{
return NO;
}


+ (ComponentDescriptorProvider)componentDescriptorProvider
{
return concreteComponentDescriptorProvider<FabricLookViewComponentDescriptor>();
Expand All @@ -30,7 +40,7 @@ - (instancetype)initWithFrame:(CGRect)frame
static const auto defaultProps = std::make_shared<const FabricLookViewProps>();
_props = defaultProps;

_view = [[UIView alloc] init];
_view = [[FabricLookComponent alloc] init];

self.contentView = _view;
}
Expand All @@ -44,8 +54,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
const auto &newViewProps = *std::static_pointer_cast<FabricLookViewProps const>(props);

if (oldViewProps.color != newViewProps.color) {
NSString * colorToConvert = [[NSString alloc] initWithUTF8String: newViewProps.color.c_str()];
[_view setBackgroundColor: [Utils hexStringToColor:colorToConvert]];
[_view setColor:RCTNSStringFromString(newViewProps.color)];
}

[super updateProps:props oldProps:oldProps];
Expand Down
20 changes: 2 additions & 18 deletions ios/FabricLookViewManager.mm
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
#import <React/RCTViewManager.h>
#import <React/RCTUIManager.h>
#import "RCTBridge.h"
#import "Utils.h"

@interface FabricLookViewManager : RCTViewManager
@end

@implementation FabricLookViewManager

RCT_EXPORT_MODULE(FabricLookView)

- (UIView *)view
{
return [[UIView alloc] init];
}
@interface RCT_EXTERN_MODULE(FabricLookViewManager, RCTViewManager)

RCT_CUSTOM_VIEW_PROPERTY(color, NSString, UIView)
{
[view setBackgroundColor: [Utils hexStringToColor:json]];
}
RCT_EXPORT_VIEW_PROPERTY(color, NSString)

@end
28 changes: 28 additions & 0 deletions ios/FabricLookViewManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// FabricLookViewManager.swift
// react-native-fabric-look
//
// Created by Yusuf Zeren on 20.05.2023.
//

import React
import UIKit

@objc(FabricLookViewManager)
public class FabricLookViewManager: RCTViewManager {
var myView: FabricLookComponent?


public override func view() -> (FabricLookComponent) {
myView = FabricLookComponent()
return myView!
}

func methodQueue() -> DispatchQueue {
return bridge.uiManager.methodQueue
}
@objc public override static func requiresMainQueueSetup() -> Bool {
return false
}

}
8 changes: 0 additions & 8 deletions ios/Utils.h

This file was deleted.

26 changes: 0 additions & 26 deletions ios/Utils.m

This file was deleted.

4 changes: 4 additions & 0 deletions react-native-fabric-look-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//

37 changes: 19 additions & 18 deletions react-native-fabric-look.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,27 @@ Pod::Spec.new do |s|
s.license = package["license"]
s.authors = package["author"]

s.platforms = { :ios => "11.0" }
s.platforms = { :ios => "12.0" }
s.source = { :git => "https://github.com/ysfzrn/react-native-fabric-look.git", :tag => "#{s.version}" }

s.source_files = "ios/**/*.{h,m,mm}"

s.dependency "React-Core"
s.source_files = "ios/**/*.{h,m,mm,swift}"

# Don't install the dependencies when we run `pod install` in the old architecture.
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
}
s.dependency "React-RCTFabric"
s.dependency "React-Codegen"
s.dependency "RCT-Folly"
s.dependency "RCTRequired"
s.dependency "RCTTypeSafety"
s.dependency "ReactCommon/turbomodule/core"
end
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
s.pod_target_xcconfig = {
"DEFINES_MODULE" => "YES",
#"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
#"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
#"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
"SWIFT_OBJC_INTERFACE_HEADER_NAME" => "react-native-fabric-look-Swift.h",
"OTHER_SWIFT_FLAGS" => "-DNATIVE_LIST_PACKAGE_NEW_ARCH_ENABLED"
}
else
s.pod_target_xcconfig = {
"DEFINES_MODULE" => "YES",
"SWIFT_OBJC_INTERFACE_HEADER_NAME" => "react-native-fabric-look-Swift.h"
}
end
install_modules_dependencies(s)
end