Skip to content

feat: customizing app with dream11 configuration #1309

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

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
42 changes: 40 additions & 2 deletions examples/hybrid/App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/* eslint-disable react-native/no-inline-styles */
import { ReactNode, useEffect } from 'react';
import React from 'react';
import { Button, Image, SafeAreaView, Text } from 'react-native';
import CodePush from 'react-native-code-push';
import axios from 'axios';
import { Button, Image, Platform, SafeAreaView, Text } from 'react-native';
import Instabug, {
CrashReporting,
InvocationEvent,
LogLevel,
NetworkInterceptionMode,
ReproStepsMode,
} from 'instabug-reactnative';

Expand All @@ -23,13 +26,47 @@ const throwUnhandled = () => {
throw Error('This is an unhandled JS Crash');
};

const sendGraphQLRequest = async () => {
try {
const response = await axios.post(
'https://countries.trevorblades.com/graphql',
{
query: `
query GetCountry {
country(code: "EG") {
emoji
name
}
}
`,
},
{
headers: {
'Content-Type': 'application/json',
'ibg-graphql-header': 'GetCountry',
},
},
);
console.log('Response:', response.data.data);
} catch (error) {
console.error('Error:', error);
}
};

const App: () => ReactNode = () => {
useEffect(() => {
Instabug.init({
token: 'deb1910a7342814af4e4c9210c786f35',
token: '0fcc87b8bf731164828cc411eccc802a',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which project is this token for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invocationEvents: [InvocationEvent.floatingButton],
networkInterceptionMode:
Platform.OS === 'ios' ? NetworkInterceptionMode.native : NetworkInterceptionMode.javascript,
debugLogsLevel: LogLevel.verbose,
});
CodePush.getUpdateMetadata().then((metadata) => {
if (metadata) {
Instabug.setCodePushVersion(metadata.label);
}
});
CrashReporting.setNDKCrashesEnabled(true);
Instabug.setReproStepsConfig({
all: ReproStepsMode.enabled,
Expand All @@ -55,6 +92,7 @@ const App: () => ReactNode = () => {
<Text style={{ fontSize: 21, fontWeight: '700' }}>React Native App</Text>
<Button title="Handled Crash" onPress={throwHandled} />
<Button title="Unhandled Crash" onPress={throwUnhandled} />
<Button title="Send GQL Request" onPress={sendGraphQLRequest} />
</SafeAreaView>
);
};
Expand Down
4 changes: 3 additions & 1 deletion examples/hybrid/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {

}

apply from: "../../node_modules/instabug-reactnative/android/native.gradle"
android {
signingConfigs {
debug {
Expand Down Expand Up @@ -57,6 +58,7 @@ dependencies {
def composeBom = platform('androidx.compose:compose-bom:2023.10.00')
implementation composeBom
androidTestImplementation composeBom
implementation project(':react-native-code-push')

// Compose dependencies
implementation "androidx.compose.ui:ui"
Expand All @@ -72,7 +74,7 @@ dependencies {
implementation libs.androidx.annotation.experimental
implementation "com.facebook.react:react-android"
implementation "com.facebook.react:hermes-android"
// Other dependencies...
implementation "com.instabug.library:instabug-with-okhttp-interceptor:${project.ext.instabug.version}"
}
configurations.all {
resolutionStrategy {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
package com.instabug.hybridsampleapp;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.instabug.reactlibrary.RNInstabug;

import android.app.Application;
import android.util.Log;
import com.instabug.library.LogLevel;
import com.instabug.library.invocation.InstabugInvocationEvent;
import com.microsoft.codepush.react.CodePush;

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

public class HybridApplication extends Application {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
protected String getJSBundleFile() {
return CodePush.getJSBundleFile();
}

@Override
public boolean getUseDeveloperSupport() {
return false;
}

@Override
protected List<ReactPackage> getPackages() {
return Collections.emptyList();
}
};
@Override
public void onCreate() {
super.onCreate();
Log.v("Instabug-Hybrid", "starting from native");

new RNInstabug.Builder(this, "deb1910a7342814af4e4c9210c786f35")
new RNInstabug.Builder(this, "0fcc87b8bf731164828cc411eccc802a")
.setInvocationEvents(InstabugInvocationEvent.SHAKE, InstabugInvocationEvent.FLOATING_BUTTON)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,62 @@
package com.instabug.hybridsampleapp;

import com.instabug.library.logging.listeners.networklogs.NetworkLogListener;
import com.instabug.library.logging.listeners.networklogs.NetworkLogSnapshot;
import com.microsoft.codepush.react.CodePush;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;
import com.instabug.crash.CrashReporting;
import com.instabug.crash.models.IBGNonFatalException;
import com.instabug.hybridsampleapp.databinding.ActivityMainBinding;
import com.instabug.library.okhttplogger.InstabugOkhttpInterceptor;

import org.json.JSONObject;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
private ActivityMainBinding binding;
private final OkHttpClient client; // Make it final
NetworkLogListener networkLogListener = new NetworkLogListener() {
@Override
public NetworkLogSnapshot onNetworkLogCaptured(NetworkLogSnapshot networkLog) {
return networkLog;
}
};
public MainActivity() {
InstabugOkhttpInterceptor instabugOkhttpInterceptor = new InstabugOkhttpInterceptor();
instabugOkhttpInterceptor.registerNetworkLogsListener(networkLogListener);
client = new OkHttpClient.Builder()
.addInterceptor(instabugOkhttpInterceptor)
.build();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

binding.buttonReactNative.setOnClickListener(view -> {
Intent intent = new Intent(MainActivity.this, ReactNativeAppActivity.class);
startActivity(intent);
});


binding.buttonHandled.setOnClickListener(view -> {
Map<String, String> attributes = new HashMap<>();
Expand All @@ -39,5 +73,67 @@ protected void onCreate(Bundle savedInstanceState) {
binding.buttonUnhandled.setOnClickListener(view -> {
throw new Error("Unhandled Java Crash");
});

binding.buttonGraphQL.setOnClickListener(view -> {
if (client != null) {
sendGraphQLRequest();
} else {
Log.e(TAG, "OkHttpClient is null");
Toast.makeText(this, "Error: HTTP Client not initialized", Toast.LENGTH_SHORT).show();
}
});
}

private void sendGraphQLRequest() {
String graphqlQuery = "{"
+ "\"query\": \"query GetCountry { "
+ " country(code: \\\"EG\\\") { "
+ " emoji "
+ " name "
+ " }"
+ "}\""
+ "}";

MediaType JSON = MediaType.parse("application/json; charset=utf-8");
RequestBody body = RequestBody.create(JSON, graphqlQuery);

Request request = new Request.Builder()
.url("https://countries.trevorblades.com/graphql")
.post(body)
.addHeader("Content-Type", "application/json")
.addHeader("ibg-graphql-header", "GetCountry")
.build();

client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.e(TAG, "Request failed: " + e.getMessage());
runOnUiThread(() -> {
Toast.makeText(MainActivity.this,
"Error: " + e.getMessage(),
Toast.LENGTH_SHORT).show();
});
}

@Override
public void onResponse(Call call, Response response) throws IOException {
final String responseData = response.body().string();
runOnUiThread(() -> {
try {
JSONObject jsonObject = new JSONObject(responseData);
String result = jsonObject.getJSONObject("data").toString();
Toast.makeText(MainActivity.this,
"Response: " + result,
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Log.e(TAG, "Error parsing response: " + e.getMessage());
Toast.makeText(MainActivity.this,
"Error parsing response: " + e.getMessage(),
Toast.LENGTH_SHORT).show();
}
});
response.close();
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unhandled Crash" />
<Button
android:id="@+id/buttonGraphQL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send GraphQL Request" />
</LinearLayout>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">HybridSampleApp</string>
<string moduleConfig="true" name="CodePushDeploymentKey">DeploymentKey</string>
</resources>
3 changes: 3 additions & 0 deletions examples/hybrid/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ include ':app'
includeBuild('../node_modules/@react-native/gradle-plugin')



include ':app', ':react-native-code-push'
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
Loading