Giter Site home page Giter Site logo

a-eid / react-native-window-view Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wolewicki/react-native-window-view

0.0 1.0 0.0 616 KB

Native iOS component for rendering views straight under the UIWindow

License: MIT License

Java 37.48% JavaScript 7.07% TypeScript 14.98% Swift 0.30% Ruby 5.77% C 0.49% Objective-C 33.91%

react-native-window-view's Introduction

react-native-window-view

Native component for rendering views straight under the Window. Based on RCTPerfMonitor.

Installation

npm install react-native-window-view

Usage

import * as React from 'react';

import { Button, StyleSheet, View } from 'react-native';
import RNWindowView from 'react-native-window-view';

export default function App() {
  const [shown, setShown] = React.useState(true);

  return (
    <View style={styles.container}>
      <Button title="Show/hide window view" onPress={() => setShown(!shown)} />
      <RNWindowView shown={shown}>
        <View style={styles.box} />
      </RNWindowView>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'flex-start',
    justifyContent: 'center',
  },
  box: {
    width: 40,
    height: 40,
    borderRadius: 10,
    borderWidth: 2,
    borderColor: 'black',
    backgroundColor: 'red',
  },
});

you also need to add the following code to your appDelegate.m.

#import <react-native-window-view/RNWindowView.h>

@implementation RNWindow

- (UIView *) hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    UIView *hitTestResult = [super hitTest:point withEvent:event];
    if ([hitTestResult isKindOfClass:[RNWindow class]]) {
      return nil;
    }
    return hitTestResult;
}

- (void)didAddSubview:(UIView *)subview
{
  if (![subview isKindOfClass:[RNViewContainer class]]) {
    for (UIView *view in self.subviews) {
      if ([view isKindOfClass:[RNViewContainer class]]) {
        [self bringSubviewToFront:view];
      }
    }
  }
}

@end

@implementation AppDelegate


// inside didFinishLaunchingWithOptions replace this line

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

// with this

self.window = [[RNWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

react-native-window-view's People

Contributors

wolewicki avatar a-eid avatar dependabot[bot] avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.