Skip to content

Commit 756350f

Browse files
committed
feat: run android
1 parent 5f531c7 commit 756350f

File tree

4 files changed

+73
-7
lines changed

4 files changed

+73
-7
lines changed

RNFastImage.podspec

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
require 'json'
22

3+
fabric_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1'
4+
35
Pod::Spec.new do |s|
46
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
57

@@ -9,13 +11,34 @@ Pod::Spec.new do |s|
911
s.authors = { "Dylan Vann" => "[email protected]" }
1012
s.homepage = "https://github.com/DylanVann/react-native-fast-image#readme"
1113
s.license = "MIT"
12-
s.platforms = { :ios => "8.0", :tvos => "9.0" }
13-
s.framework = 'UIKit'
1414
s.requires_arc = true
15+
s.framework = 'UIKit'
1516
s.source = { :git => "https://github.com/DylanVann/react-native-fast-image.git", :tag => "v#{s.version}" }
16-
s.source_files = "ios/**/*.{h,m}"
1717

18-
s.dependency 'React-Core'
18+
if fabric_enabled
19+
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
20+
21+
s.pod_target_xcconfig = {
22+
'HEADER_SEARCH_PATHS' => '"$(PODS_ROOT)/boost" "$(PODS_ROOT)/boost-for-react-native" "$(PODS_ROOT)/RCT-Folly"',
23+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
24+
}
25+
s.platforms = { ios: '11.0', tvos: '11.0' }
26+
s.compiler_flags = folly_compiler_flags + ' -DRCT_NEW_ARCH_ENABLED'
27+
s.source_files = 'ios/**/*.{h,m,mm,cpp}'
28+
29+
s.dependency "React"
30+
s.dependency "React-RCTFabric"
31+
s.dependency "React-Codegen"
32+
s.dependency "RCT-Folly"
33+
s.dependency "RCTRequired"
34+
s.dependency "RCTTypeSafety"
35+
s.dependency "ReactCommon/turbomodule/core"
36+
else
37+
s.platforms = { :ios => "8.0", :tvos => "9.0" }
38+
s.source_files = "ios/**/*.{h,mm}"
39+
s.dependency 'React-Core'
40+
end
41+
1942
s.dependency 'SDWebImage', '~> 5.11.1'
2043
s.dependency 'SDWebImageWebPCoder', '~> 0.8.4'
2144
end

android/build.gradle

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,23 @@ buildscript {
1212
mavenCentral()
1313
}
1414
dependencies {
15-
classpath 'com.android.tools.build:gradle:3.5.3'
15+
classpath 'com.android.tools.build:gradle:7.2.1'
1616
}
1717
}
1818
}
1919

20+
def isNewArchitectureEnabled() {
21+
// To opt-in for the New Architecture, you can either:
22+
// - Set `newArchEnabled` to true inside the `gradle.properties` file
23+
// - Invoke gradle with `-newArchEnabled=true`
24+
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
25+
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
26+
}
27+
28+
if (isNewArchitectureEnabled()) {
29+
apply plugin: "com.facebook.react"
30+
}
31+
2032
apply plugin: 'com.android.library'
2133

2234
android {
@@ -61,7 +73,11 @@ def glideVersion = safeExtGet('glideVersion', '4.12.0')
6173

6274
dependencies {
6375
//noinspection GradleDynamicVersion
64-
implementation 'com.facebook.react:react-native:+' // From node_modules
76+
if (isNewArchitectureEnabled()) {
77+
implementation project(":ReactAndroid")
78+
} else {
79+
implementation 'com.facebook.react:react-native:+'
80+
}
6581
implementation "com.github.bumptech.glide:glide:${glideVersion}"
6682
implementation "com.github.bumptech.glide:okhttp3-integration:${glideVersion}"
6783
annotationProcessor "com.github.bumptech.glide:compiler:${glideVersion}"

android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@
2323
import com.facebook.react.uimanager.annotations.ReactProp;
2424
import com.facebook.react.uimanager.events.RCTEventEmitter;
2525
import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper;
26+
import com.facebook.react.uimanager.ViewManagerDelegate;
27+
import com.facebook.react.viewmanagers.FastImageViewManagerDelegate;
28+
import com.facebook.react.viewmanagers.FastImageViewManagerInterface;
2629

2730
import java.util.List;
2831
import java.util.Map;
2932
import java.util.WeakHashMap;
3033

3134
import javax.annotation.Nullable;
3235

33-
class FastImageViewManager extends SimpleViewManager<FastImageViewWithUrl> implements FastImageProgressListener {
36+
class FastImageViewManager extends SimpleViewManager<FastImageViewWithUrl> implements FastImageProgressListener, FastImageViewManagerInterface<FastImageViewWithUrl> {
3437

3538
static final String REACT_CLASS = "FastImageView";
3639
static final String REACT_ON_LOAD_START_EVENT = "onFastImageLoadStart";
@@ -39,6 +42,18 @@ class FastImageViewManager extends SimpleViewManager<FastImageViewWithUrl> imple
3942

4043
@Nullable
4144
private RequestManager requestManager = null;
45+
private final ViewManagerDelegate<FastImageViewWithUrl> mDelegate;
46+
47+
48+
@Nullable
49+
@Override
50+
protected ViewManagerDelegate<FastImageViewWithUrl> getDelegate() {
51+
return mDelegate;
52+
}
53+
54+
public FastImageViewManager() {
55+
mDelegate = new FastImageViewManagerDelegate<>(this);
56+
}
4257

4358
@NonNull
4459
@Override
@@ -56,18 +71,21 @@ protected FastImageViewWithUrl createViewInstance(@NonNull ThemedReactContext re
5671
return new FastImageViewWithUrl(reactContext);
5772
}
5873

74+
@Override
5975
@ReactProp(name = "source")
6076
public void setSource(FastImageViewWithUrl view, @Nullable ReadableMap source) {
6177
view.setSource(source);
6278
}
6379

80+
@Override
6481
@ReactProp(name = "defaultSource")
6582
public void setDefaultSource(FastImageViewWithUrl view, @Nullable String source) {
6683
view.setDefaultSource(
6784
ResourceDrawableIdHelper.getInstance()
6885
.getResourceDrawable(view.getContext(), source));
6986
}
7087

88+
@Override
7189
@ReactProp(name = "tintColor", customType = "Color")
7290
public void setTintColor(FastImageViewWithUrl view, @Nullable Integer color) {
7391
if (color == null) {
@@ -77,6 +95,7 @@ public void setTintColor(FastImageViewWithUrl view, @Nullable Integer color) {
7795
}
7896
}
7997

98+
@Override
8099
@ReactProp(name = "resizeMode")
81100
public void setResizeMode(FastImageViewWithUrl view, String resizeMode) {
82101
final FastImageViewWithUrl.ScaleType scaleType = FastImageViewConverter.getScaleType(resizeMode);

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,13 @@
7878
"peerDependencies": {
7979
"react": "^17 || ^18",
8080
"react-native": ">=0.60.0"
81+
},
82+
"codegenConfig": {
83+
"name": "rnfastimage",
84+
"type": "all",
85+
"jsSrcsDir": "./src",
86+
"android": {
87+
"javaPackageName": "com.dylanvann.fastimage"
88+
}
8189
}
8290
}

0 commit comments

Comments
 (0)