-
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.
- Loading branch information
0 parents
commit 906e4bf
Showing
16 changed files
with
14,335 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# OSX | ||
# | ||
.DS_Store | ||
|
||
# node.js | ||
# | ||
node_modules/ | ||
npm-debug.log | ||
yarn-error.log | ||
|
||
# Xcode | ||
# | ||
build/ | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata | ||
*.xccheckout | ||
*.moved-aside | ||
DerivedData | ||
*.hmap | ||
*.ipa | ||
*.xcuserstate | ||
project.xcworkspace | ||
|
||
# Android/IntelliJ | ||
# | ||
build/ | ||
.idea | ||
.gradle | ||
local.properties | ||
*.iml | ||
|
||
# BUCK | ||
buck-out/ | ||
\.buckd/ | ||
*.keystore |
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 @@ | ||
# react-native-jewel-carousel | ||
|
||
## Getting started | ||
|
||
`$ npm install react-native-jewel-carousel --save` | ||
|
||
### Mostly automatic installation | ||
|
||
`$ react-native link react-native-jewel-carousel` | ||
|
||
## Usage | ||
```javascript | ||
import JewelCarousel from 'react-native-jewel-carousel'; | ||
|
||
// TODO: What to do with the module? | ||
JewelCarousel; | ||
``` |
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,14 @@ | ||
README | ||
====== | ||
|
||
If you want to publish the lib as a maven dependency, follow these steps before publishing a new version to npm: | ||
|
||
1. Be sure to have the Android [SDK](https://developer.android.com/studio/index.html) and [NDK](https://developer.android.com/ndk/guides/index.html) installed | ||
2. Be sure to have a `local.properties` file in this folder that points to the Android SDK and NDK | ||
``` | ||
ndk.dir=/Users/{username}/Library/Android/sdk/ndk-bundle | ||
sdk.dir=/Users/{username}/Library/Android/sdk | ||
``` | ||
3. Delete the `maven` folder | ||
4. Run `./gradlew installArchives` | ||
5. Verify that latest set of generated files is in the maven folder with the correct version number |
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,148 @@ | ||
// android/build.gradle | ||
|
||
// based on: | ||
// | ||
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle | ||
// previous location: | ||
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/build.gradle | ||
// | ||
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/app/build.gradle | ||
// previous location: | ||
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle | ||
|
||
// These defaults should reflect the SDK versions used by | ||
// the minimum React Native version supported. | ||
def DEFAULT_COMPILE_SDK_VERSION = 28 | ||
def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3' | ||
def DEFAULT_MIN_SDK_VERSION = 16 | ||
def DEFAULT_TARGET_SDK_VERSION = 28 | ||
|
||
def safeExtGet(prop, fallback) { | ||
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback | ||
} | ||
|
||
apply plugin: 'com.android.library' | ||
apply plugin: 'maven' | ||
|
||
buildscript { | ||
// The Android Gradle plugin is only required when opening the android folder stand-alone. | ||
// This avoids unnecessary downloads and potential conflicts when the library is included as a | ||
// module dependency in an application project. | ||
// ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies | ||
if (project == rootProject) { | ||
repositories { | ||
google() | ||
} | ||
dependencies { | ||
// This should reflect the Gradle plugin version used by | ||
// the minimum React Native version supported. | ||
classpath 'com.android.tools.build:gradle:3.4.1' | ||
} | ||
} | ||
} | ||
|
||
android { | ||
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION) | ||
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION) | ||
defaultConfig { | ||
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION) | ||
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION) | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
lintOptions { | ||
abortOnError false | ||
} | ||
} | ||
|
||
repositories { | ||
// ref: https://www.baeldung.com/maven-local-repository | ||
mavenLocal() | ||
maven { | ||
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm | ||
url "$rootDir/../node_modules/react-native/android" | ||
} | ||
maven { | ||
// Android JSC is installed from npm | ||
url "$rootDir/../node_modules/jsc-android/dist" | ||
} | ||
google() | ||
} | ||
|
||
dependencies { | ||
//noinspection GradleDynamicVersion | ||
implementation 'com.facebook.react:react-native:+' // From node_modules | ||
} | ||
|
||
def configureReactNativePom(def pom) { | ||
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text) | ||
|
||
pom.project { | ||
name packageJson.title | ||
artifactId packageJson.name | ||
version = packageJson.version | ||
group = "com.reactlibrary" | ||
description packageJson.description | ||
url packageJson.repository.baseUrl | ||
|
||
licenses { | ||
license { | ||
name packageJson.license | ||
url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename | ||
distribution 'repo' | ||
} | ||
} | ||
|
||
developers { | ||
developer { | ||
id packageJson.author.username | ||
name packageJson.author.name | ||
} | ||
} | ||
} | ||
} | ||
|
||
afterEvaluate { project -> | ||
// some Gradle build hooks ref: | ||
// https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html | ||
task androidJavadoc(type: Javadoc) { | ||
source = android.sourceSets.main.java.srcDirs | ||
classpath += files(android.bootClasspath) | ||
classpath += files(project.getConfigurations().getByName('compile').asList()) | ||
include '**/*.java' | ||
} | ||
|
||
task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) { | ||
classifier = 'javadoc' | ||
from androidJavadoc.destinationDir | ||
} | ||
|
||
task androidSourcesJar(type: Jar) { | ||
classifier = 'sources' | ||
from android.sourceSets.main.java.srcDirs | ||
include '**/*.java' | ||
} | ||
|
||
android.libraryVariants.all { variant -> | ||
def name = variant.name.capitalize() | ||
def javaCompileTask = variant.javaCompileProvider.get() | ||
|
||
task "jar${name}"(type: Jar, dependsOn: javaCompileTask) { | ||
from javaCompileTask.destinationDir | ||
} | ||
} | ||
|
||
artifacts { | ||
archives androidSourcesJar | ||
archives androidJavadocJar | ||
} | ||
|
||
task installArchives(type: Upload) { | ||
configuration = configurations.archives | ||
repositories.mavenDeployer { | ||
// Deploy to react-native-event-bridge/maven, ready to publish to npm | ||
repository url: "file://${projectDir}/../android/maven" | ||
configureReactNativePom pom | ||
} | ||
} | ||
} |
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,6 @@ | ||
<!-- AndroidManifest.xml --> | ||
|
||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.reactlibrary"> | ||
|
||
</manifest> |
29 changes: 29 additions & 0 deletions
29
android/src/main/java/com/reactlibrary/JewelCarouselModule.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,29 @@ | ||
// JewelCarouselModule.java | ||
|
||
package com.reactlibrary; | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
import com.facebook.react.bridge.Callback; | ||
|
||
public class JewelCarouselModule extends ReactContextBaseJavaModule { | ||
|
||
private final ReactApplicationContext reactContext; | ||
|
||
public JewelCarouselModule(ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
this.reactContext = reactContext; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "JewelCarousel"; | ||
} | ||
|
||
@ReactMethod | ||
public void sampleMethod(String stringArgument, int numberArgument, Callback callback) { | ||
// TODO: Implement some actually useful functionality | ||
callback.invoke("Received numberArgument: " + numberArgument + " stringArgument: " + stringArgument); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
android/src/main/java/com/reactlibrary/JewelCarouselPackage.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,24 @@ | ||
// JewelCarouselPackage.java | ||
|
||
package com.reactlibrary; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.uimanager.ViewManager; | ||
|
||
public class JewelCarouselPackage implements ReactPackage { | ||
@Override | ||
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) { | ||
return Arrays.<NativeModule>asList(new JewelCarouselModule(reactContext)); | ||
} | ||
|
||
@Override | ||
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) { | ||
return Collections.emptyList(); | ||
} | ||
} |
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,10 @@ | ||
const API_BASE_URL = 'https://repersonalize.jewelml.io/c/p/'; | ||
|
||
export function getPersonalizationURL(key, model, item_id, unique_id) { | ||
return `${API_BASE_URL}${key}/l?integration_id=${key}&model=${model}&item_id=${item_id}&unique_id=${unique_id}` | ||
} | ||
|
||
export async function getPersonalizationData(key, model, item_id, unique_id) { | ||
return fetch(getPersonalizationURL(key, model, item_id, unique_id)) | ||
.then((response) => response.json()) | ||
} |
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,84 @@ | ||
// main index.js | ||
|
||
import React, {useState, useEffect} from 'react' | ||
import {View, Image, Text, TouchableOpacity, ActivityIndicator} from 'react-native' | ||
import Carousel, {Pagination} from 'react-native-snap-carousel' | ||
|
||
import {getPersonalizationData} from './api' | ||
|
||
const CarouselImage = (uri) => { | ||
return ( | ||
<View> | ||
<Image source={{uri: uri}} /> | ||
</View> | ||
) | ||
} | ||
|
||
const CarouselText = (text) => { | ||
return ( | ||
<View> | ||
<Text>{text}</Text> | ||
</View> | ||
) | ||
} | ||
|
||
const CarouselEntry = (image, text) => { | ||
return ( | ||
<TouchableOpacity activeOpacity={1}> | ||
<CarouselImage uri={image}/> | ||
<CarouselText text={text}/> | ||
</TouchableOpacity> | ||
) | ||
} | ||
|
||
const PersonalizationCarousel = (key, item_id, model, unique_id = '') => { | ||
const [items, setItems] = useState([]) | ||
const [isLoading, setIsLoading] = useState(false) | ||
const [activeSlide, setActiveSlide] = useState(0) | ||
|
||
useEffect(() => { | ||
setIsLoading(true) | ||
;(async () => { | ||
try { | ||
const response = await getPersonalizationData(key, model, item_id, unique_id) | ||
setItems(response) | ||
} catch (err) {} | ||
setIsLoading(false) | ||
})() | ||
}, [key, item_id, unique_id, model]) | ||
|
||
const renderItem = (image, text) => { | ||
return ( | ||
<CarouselEntry image={image} text={text}/> | ||
) | ||
} | ||
|
||
return isLoading ? <ActivityIndicator size="large"/> : ( | ||
<View> | ||
<Carousel | ||
data={items} | ||
renderItem={item => { | ||
return renderItem(item.standard_features.image_url_src, item.title) | ||
}} | ||
onSnapToItem={(index) => setActiveSlide(index)} | ||
loop={true} | ||
/> | ||
<Pagination | ||
dotsLength={items.length} | ||
activeDotIndex={activeSlide} | ||
containerStyle={{ backgroundColor: 'rgba(0, 0, 0, 0.75)' }} | ||
dotStyle={{ | ||
width: 10, | ||
height: 10, | ||
borderRadius: 5, | ||
marginHorizontal: 8, | ||
backgroundColor: 'rgba(255, 255, 255, 0.92)' | ||
}} | ||
inactiveDotOpacity={0.4} | ||
inactiveDotScale={0.6} | ||
/> | ||
</View> | ||
) | ||
} | ||
|
||
export default PersonalizationCarousel |
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 @@ | ||
// JewelCarousel.h | ||
|
||
#import <React/RCTBridgeModule.h> | ||
|
||
@interface JewelCarousel : NSObject <RCTBridgeModule> | ||
|
||
@end |
Oops, something went wrong.