Skip to content
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

New architecture support #90

Merged
merged 5 commits into from
Mar 19, 2023
Merged
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
19 changes: 18 additions & 1 deletion RNReactNativeHapticFeedback.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,27 @@ Pod::Spec.new do |s|
s.author = { "author" => "[email protected]" }
s.platform = :ios, "9.0"
s.source = { :git => "https://github.com/mkuczera/react-native-haptic-feedback.git", :tag => "master" }
s.source_files = "ios/*.{h,m}"
s.source_files = "ios/**/*.{h,m,mm}"
s.requires_arc = true

s.dependency 'React-Core'

# This guard prevent to install the dependencies when we run `pod install` in the old architecture.
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'

s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
}

s.dependency "React-Codegen"
s.dependency "RCT-Folly"
s.dependency "RCTRequired"
s.dependency "RCTTypeSafety"
s.dependency "ReactCommon/turbomodule/core"
end
end


80 changes: 73 additions & 7 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,41 +1,107 @@
def DEFAULT_COMPILE_SDK_VERSION = 27
def DEFAULT_BUILD_TOOLS_VERSION = "27.0.0"
def DEFAULT_TARGET_SDK_VERSION = 27
def DEFAULT_MIN_SDK_VERSION = 16
def DEFAULT_COMPILE_SDK_VERSION = 31
def DEFAULT_TARGET_SDK_VERSION = 31
def DEFAULT_MIN_SDK_VERSION = 21

buildscript {
repositories {
mavenCentral()
google()
gradlePluginPortal()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.android.tools.build:gradle:7.0.4'
}
}

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

def isNewArchitectureEnabled() {
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}

def resolveReactNativeDirectory() {
def reactNativeLocation = safeExtGet("REACT_NATIVE_NODE_MODULES_DIR", null)
if (reactNativeLocation != null) {
return file(reactNativeLocation)
}

// monorepo workaround
// react-native can be hoisted or in project's own node_modules
def reactNativeFromProjectNodeModules = file("${rootProject.projectDir}/../node_modules/react-native")
if (reactNativeFromProjectNodeModules.exists()) {
return reactNativeFromProjectNodeModules
}

def reactNativeFromNodeModulesWithHapticFeedback = file("${projectDir}/../../react-native")
if (reactNativeFromNodeModulesWithHapticFeedback.exists()) {
return reactNativeFromNodeModulesWithHapticFeedback
}

throw new Exception(
"[react-native-haptic-feedback] Unable to resolve react-native location in " +
"node_modules. You should add project extension property (in app/build.gradle) " +
"`REACT_NATIVE_NODE_MODULES_DIR` with path to react-native."
)
}

def getReactNativeMinorVersion() {
def REACT_NATIVE_DIR = resolveReactNativeDirectory()

def reactProperties = new Properties()
file("$REACT_NATIVE_DIR/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }

def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME")
def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.startsWith("0.0.0-") ? 1000 : REACT_NATIVE_VERSION.split("\\.")[1].toInteger()

return REACT_NATIVE_MINOR_VERSION
}

apply plugin: 'com.android.library'
if (isNewArchitectureEnabled()) {
apply plugin: 'com.facebook.react'
}

android {
compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION

defaultConfig {
minSdkVersion rootProject.hasProperty('minSdkVersion') ? rootProject.minSdkVersion : DEFAULT_MIN_SDK_VERSION
targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION
versionCode 1
versionName "1.0"
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
}

sourceSets {
main {
if (isNewArchitectureEnabled()) {
java.srcDirs += ['src/newarch']
} else {
java.srcDirs += ['src/oldarch']
}
}
}

lintOptions {
abortOnError false
}
}

repositories {
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$projectDir/../node_modules/react-native/android"
}
mavenCentral()
google()
}

dependencies {
if (isNewArchitectureEnabled() && getReactNativeMinorVersion() < 71) {
implementation project(":ReactAndroid")
} else {
implementation 'com.facebook.react:react-native:+'
}
}
6 changes: 3 additions & 3 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Jan 03 23:15:42 CET 2018
#Fri Oct 07 15:03:30 CEST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
zipStoreBase=GRADLE_USER_HOME

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.mkuczera;

import android.os.Vibrator;
import android.content.Context;
import android.provider.Settings;
import com.mkuczera.VibrateFactory;
import com.mkuczera.Vibrate;

import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;

public class RNReactNativeHapticFeedbackModuleImpl {

public static final String NAME = "RNHapticFeedback";

public static void trigger(ReactApplicationContext reactContext, String type, ReadableMap options) {
// Check system settings, if disabled and we're not explicitly ignoring then return immediatly
boolean ignoreAndroidSystemSettings = options.getBoolean("ignoreAndroidSystemSettings");
int hapticEnabledAndroidSystemSettings = Settings.System.getInt(reactContext.getContentResolver(), Settings.System.HAPTIC_FEEDBACK_ENABLED, 0);
if (ignoreAndroidSystemSettings == false && hapticEnabledAndroidSystemSettings == 0) return;

Vibrator v = (Vibrator) reactContext.getSystemService(Context.VIBRATOR_SERVICE);
Vibrate targetVibration = VibrateFactory.getVibration(type);

if (v == null || targetVibration == null) return;

targetVibration.apply(v);
}

}
Original file line number Diff line number Diff line change
@@ -1,28 +1,49 @@

package com.mkuczera;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import com.facebook.react.ReactPackage;
import androidx.annotation.Nullable;
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.TurboReactPackage;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.bridge.JavaScriptModule;
public class RNReactNativeHapticFeedbackPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Arrays.<NativeModule>asList(new RNReactNativeHapticFeedbackModule(reactContext));
}

// Deprecated from RN 0.47
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

public class RNReactNativeHapticFeedbackPackage extends TurboReactPackage {

@Nullable
@Override
public NativeModule getModule(String name, ReactApplicationContext reactContext) {
if (name.equals(RNReactNativeHapticFeedbackModuleImpl.NAME)) {
return new RNReactNativeHapticFeedbackModule(reactContext);
} else {
return null;
}
}

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
public ReactModuleInfoProvider getReactModuleInfoProvider() {
return () -> {
final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
moduleInfos.put(
RNReactNativeHapticFeedbackModuleImpl.NAME,
new ReactModuleInfo(
RNReactNativeHapticFeedbackModuleImpl.NAME,
RNReactNativeHapticFeedbackModuleImpl.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
isTurboModule // isTurboModule
));
return moduleInfos;
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.mkuczera;

import androidx.annotation.NonNull;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReadableMap;

public class RNReactNativeHapticFeedbackModule extends NativeHapticFeedbackSpec {

ReactApplicationContext reactContext;

RNReactNativeHapticFeedbackModule(ReactApplicationContext context) {
super(context);
this.reactContext = context;
}

@Override
@NonNull
public String getName() {
return RNReactNativeHapticFeedbackModuleImpl.NAME;
}

@Override
public void trigger(String type, ReadableMap options) {
RNReactNativeHapticFeedbackModuleImpl.trigger(this.reactContext, type, options);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.mkuczera;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;

public class RNReactNativeHapticFeedbackModule extends ReactContextBaseJavaModule {

ReactApplicationContext reactContext;

RNReactNativeHapticFeedbackModule(ReactApplicationContext context) {
super(context);
this.reactContext = context;
}

@Override
public String getName() {
return RNReactNativeHapticFeedbackModuleImpl.NAME;
}

@ReactMethod
public void trigger(String type, ReadableMap options) {
RNReactNativeHapticFeedbackModuleImpl.trigger(this.reactContext, type, options);
}
}
32 changes: 0 additions & 32 deletions index.js

This file was deleted.

Loading